- 登录到当前用户.ssh下,使用github或gitlab邮箱账号产生RSA公私钥对
cd ~/.ssh
ssh-keygen -t rsa -C "user1@gmail.com"
#回车 输入文件名默认为 id_rsa
ssh-keygen -t rsa -C "user2@gmail.com"
#回车 输入文件名不重复即可 如: id_rsa_github
- copy公钥到对应github[/gitlab]的settings中的SSH
cat id_rsa.pub | pbcopy
- 产生公私钥对之后编辑config 文件,如当前目录下没有则执行命令创建
touch config
#github
Host github.com
Hostname github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
#gitab XXX
Host XXX_git
Hostname 118.110.110.110
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
- 测试ssh
ssh -T git@github.com
Hi ... You've successfully authenticated, but GitHub does not provide shell access.
如有端口
ssh -T git@XXX_git -p 30802
Welcome to GitLab,...
- 用config文件中配置的host取代hostname即可以访问git
如: git clone ssh://git@118.110.110.110:30802/pay.git
改为:
git clone ssh://git@XXX_git:30802/pay.git