mac 系統(tǒng)下坤按,多個 ssh公鑰 創(chuàng)建添加
xxx@xxx.xxx 替換成對應(yīng)的賬號郵箱
普通權(quán)限與root權(quán)限的區(qū)別就是路徑地址不同
普通權(quán)限:~/.ssh/
root權(quán)限:/var/root/.ssh/
創(chuàng)建 github SSH-KEY
1:生成
按照提示完成三次回車
ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f ~/.ssh/github_id_rsa
# sudo ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f /var/root/.ssh/github_id_rsa
2:查看 ssh key
cat ~/.ssh/github_id_rsa.pub
# sudo cat /var/root/.ssh/github_id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABA....
3:復(fù)制內(nèi)容到 github 添加 SSH key
創(chuàng)建 gitee(碼云) SSH-KEY
1:生成
按照提示完成三次回車
ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f ~/.ssh/gitee_id_rsa
# sudo ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f /var/root/.ssh/gitee_id_rsa
2:查看 ssh key
cat ~/.ssh/gitee_id_rsa.pub
# sudo cat /var/root/.ssh/gitee_id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
3:復(fù)制內(nèi)容到 gitee 添加 SSH key
創(chuàng)建 SSH 用戶配置文件 config
touch ~/.ssh/config
# sudo touch /var/root/.ssh/config
添加以下內(nèi)容
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
# IdentityFile /var/root/.ssh/github_id_rsa
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# IdentityFile /var/root/.ssh/gitee_id_rsa
Host 和 HostName 填寫 git 服務(wù)器的域名
IdentityFile 指定私鑰的路徑
測試
ssh -T git@github.com
# sudo ssh -T git@github.com
# Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@gitee.com
# Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
2020/01/17
遇到了一個問題:使用ssh推送代碼到遠(yuǎn)程git服務(wù)器報錯寝志,ssh 配置正常沒有做任何的修改
ssh: Could not resolve hostname [git.xxx.com](http://git.xxx.com):
nodename nor servname provided, or not known
fatal: 無法讀取遠(yuǎn)程倉庫淀零。
解決辦法:
ssh-keyscan -H git.xxx.com >> ~/.ssh/known_hosts