前言
本教材适用于gitlab 和GitHub。同样最近CSDN推出了基于gitlab的codechina.csdn.net,你赶紧来试试吧!
I 免密码进行SSH连接
- 创建rsa:
ssh-keygen -t rsa -b 4096 -C "929118967@qq.com"
- 配置config:
➜ .ssh touch config
- 使用pbcopy或者ssh-copy-id进行拷贝公钥到对应的远程服务器
➜ .ssh pbcopy < ~/.ssh/qctmac_id_rsa.pub
使用ssh-copy-id进行报备
ssh-copy-id:千万不要把私钥泄漏!只是把公钥(*.pub 文件)复制给远程服务器;
$ ssh-copy-id -i ~/.ssh/id_rsa_Theos125 root@192.168.2.144
(IP+默认端口 这里拷贝的是公钥,,如果是指定私钥ssh-copy-id 会自己寻找公钥。)
如果是配置在公司Mac上,记得设置密码,并在更换Mac时移除掉 ~/.ssh/ 目录下的xx_id_rsa/xx_id_rsa.pub
。
1.1 创建 rsa
ssh-keygen -t rsa -b 4096 -C "929118967@qq.com"
1.2 配置 ssh config
config文件的 语法
Host 别名 HostName:是目标主机的主机名,也就是平时我们使用ssh后面跟的地址名称。 Port:指定的端口号。 User:指定的登陆用户名。 IdentifyFile:指定的私钥地址。
# Private 192.168.2.125 Host iphone HostName 192.168.2.125 User root IdentityFile ~/.ssh/id_rsa_Theos125 # Private github Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa # git clone git@codechina.csdn.net:u011018979/resume.git Host codechina.csdn.net HostName codechina.csdn.net User git IdentityFile ~/.ssh/qctmac_id_rsa
1.3 测试连接
➜ csdn ssh -T git@codechina.csdn.net Enter passphrase for key '/Users/mac/.ssh/qctmac_id_rsa': Welcome to GitLab, @u011018979!
连接iPhone
$ ssh iPhone root@192.168.2.125's password: iPhone:~ root#
1.4 案例:配置GitHub SSH keys
Enter ls -al ~/.ssh to see if existing SSH keys are present:
If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.
ssh-keygen -t rsa -b 4096 -C "929118967@qq.com"
添加对应的公钥到对应的远程服务器:.ssh pbcopy < ~/.ssh/qctmac_id_rsa.pub
配置邮箱和用户名: git config --global --edit
修改 author :git commit --amend --reset-author
效果