免登錄配置
在ssh終端中輸入
ssh-keygen -t rsa
執(zhí)行后 一路回車(3次)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/XXX/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/XXX/.ssh/id_rsa.
Your public key has been saved in /Users/XXX/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:qw8xn3RgwjcPYcVjcAbbIYusAC2sDrBlHAY7B2IykmA XXX@XXX-MacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
|XBE. *== |
|OO= o o O+. |
|==o = O.. |
|+o . . + = |
|o . o S o |
| . = + |
| . + |
| o |
| ... |
+----[SHA256]-----+
然后登錄你GitHub賬號 依次點擊"Setting" -> "SSH Keys"->"New SSH key"
將id_rsa.pub中的內(nèi)容copy到 key那一欄 title是個簡單的說明
最后測試是否成功7炱洹!
ssh -T git@github.com
會出現(xiàn)
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
yes 回車
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Hi XXXX! You've successfully authenticated, but GitHub does not provide shell access.
那么你就成功的完成了免登錄配置
多賬號登錄
如果你有好幾個git賬號那么你要下面操作了
在ssh終端中輸入
ssh-keygen -t rsa -C "你的github賬號" -f ~/.ssh/秘鑰文件名稱(例如: github_1_rsa)
執(zhí)行后 一路回車(2次 ,因為你已經(jīng)設(shè)置了名稱)
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/XXX/.ssh/github_1_rsa.
Your public key has been saved in /Users/XXX/.ssh/github_1_rsa.pub.
The key fingerprint is:
SHA256:dZFCgwLaaDxVW7W+v4UfXeyB8ysKr5GRg9f+yqcf1vX 1aa@company.com(你的github賬號)
The key's randomart image is:
+---[RSA 2048]----+
| oo. .++ .. |
| . = .o. .o. |
| * . .. o.. |
| . . .oo. .. |
| .S=.. o .o|
| . =. .=oo|
| +...oo+o|
| =.o=..o|
| ..*O+o.E|
+----[SHA256]-----+
然后和上面操作一樣將 github_1_rsa.pub 的內(nèi)容加入 GitHub的ssh管理器中
給ssh 創(chuàng)建配置文件
vim ~/.shh/config (默認是沒有該文件的)
## 配置寫入
Host github.com(自定義名稱)
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host my.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_1_rsa
使用:
// 原來寫法
git clone git@github.com: github用戶名/testgit.git
// 現(xiàn)在寫法
git clone git@my.github.com: my的github的用戶名/testgit.git
github提示Permission denied (publickey)
極大多數(shù)情況是由于github賬號沒有設(shè)置ssh公鑰信息所致执俩。 前往 GitHub 網(wǎng)站的"account settings"
如果你在新建秘鑰的時候使用了自定義的名稱壹粟,比如github_rsa听哭,你需要再配置一個config文件
cd ~/.ssh
vi config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa