匯入public key到online git server
有些專案需要事先提供public key到平台上,才可以使用專案
方法主要分兩個步驟:
步驟1.add your key to git platform
步驟2.Check your SSH access
…
步驟1.add your key to git platform
1.check whether exist ssh key
# ls -al ~/.ssh
如果沒有key就透過步驟2產生key
如果有key就直接到步驟3輸出key
2.Generating a new SSH key
# ssh-keygen -t rsa -b 4096 -C “raymond0820@gmail.com”
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): < 連到git server會用到自訂密碼>
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
8a:90:57:10:6f:57:4f:0e:ef:cb:fb:2a:95:4a:f5:01 raymond0820@gmail.com
The key’s randomart image is:
+–[ RSA 4096]—-+
| o. o . |
| o . *E |
| + . +. |
| . o . .. . |
| o . S ..o . |
| o . . ..o.. |
| . . . oo |
| o . |
| .oo. |
+—————–+
3.output you key and paste to github or gitlab
# cat ~/.ssh/id_rsa.pub
4.(optional) Adding key to the ssh-agent
# ssh-add ~/.ssh/id_rsa
refer
Adding a new SSH key to your GitHub account.
https://help.github.com/articles/generating-an-ssh-key/
…
步驟2.Check your SSH access
確保local和online git server之間的底層傳輸是否正確
#ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address ‘192.30.253.113’ to the list of known hosts.
Enter passphrase for key ‘/root/.ssh/id_rsa’: < 這邊要輸入做key時用的passphrase>
Hi Raymond0820! You’ve successfully authenticated, but GitHub does not provide shell access.
or
#ssh -T -ai ~/.ssh/id_rsa_raymond0820 git@github.com
Enter passphrase for key ‘/root/.ssh/id_rsa_raymond0820’:
Hi Raymond0820! You’ve successfully authenticated, but GitHub does not provide shell access.
ps:
若事前沒有先提供public key到git-hub,則會出現Permission denied (publickey).
#ssh -T -ai ~/.ssh/id_rsa_raymondtestproject git@github.com
Enter passphrase for key ‘/root/.ssh/id_rsa_raymondtestproject’:
Permission denied (publickey).
ps:
若出現ssh: connect to host github.com port 22: Connection refused
編輯.ssh/config
Host github.com
User < email >
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
在執行ssh -T git@github.com做測試
refer
http://blog.csdn.net/fulinus/article/details/38542439