1. 程式人生 > >git設定ssh訪問

git設定ssh訪問

生成新的ssh金鑰

進入根目錄的.ssh裡,沒有也行,生成檔名時會生成目錄的

cd ~/.ssh

生成檔名和檔案位置

ssh-keygen -t rsa -C "github" -f id_rsa_github

指定生成的檔名是id_rsa_github
指定備註是github
密碼一般為空即可
此時的~/.ssh目錄下會有:

  • id_rsa_github 私鑰檔案
  • id_rsa_github.pub 公鑰檔案

再把key加到ssh-agent裡

Start the ssh-agent in the background.

eval "$(ssh-agent -s)"
Agent pid 59566

If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

ssh-add -K ~/.ssh/id_rsa

再把.pub裡的加到github的ssh key裡
注意:生成的檔名是什麼,加到config裡的file名字就用自己生成的,ssh-add的也是

此時git clone git://地址 就OK了

參考地址github官網