我們先切換目錄。cd ~/.ssh/,如果報錯,則新建。
cd ~/.ssh/
#mkdir ~/.ssh //新建
接著按下面命令來生成 sshkey:
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
按照提示完成三次回車(key直接回車會默認是id_isa,設置密碼為空),即可生成 ssh key
**下一步非常重要:在.ssh 中添加config文件 輸入對應的host信息
cd ~/.ssh
touch config
執(zhí)行open config 打開config文件 然后輸入一下內容保存
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/github_rsa
然后,我們就可以配置,Git 的全局用戶名和郵箱了。jie
cat id_rsa.pub
復制 接下來登錄git--profile Setting--ssh keys
git config --global user.name "yourname"
git config --global user.email "youremail"
#HostkeyAlgorithms +ssh-dss
Host git.xxxxx.com
HostName git.xxxxxx.com
PubkeyAcceptedKeyTypes +ssh-dss
HostkeyAlgorithms +ssh-dss
IdentityFile ~/.ssh/id_rsa
Host git.coding.net
HostName git.coding.net
PreferredAuthentications publickey
User xxxxx@xxxxxx.com
IdentityFile ~/.ssh/id_rsa