github添加ssh公鑰

    使用git做爲版本維護工具很是方便,並且通常我的用github做爲遠端庫就夠用了。而通常git鏈接github的方式採用ssh的方法,http的會略微慢一些。因此爲了方便通常會在github設置中添加經常使用電腦的SSH公鑰。python

    生成RSA

    首先確認是否安裝了ssh工具:git

[yu@yu learn]$ ssh
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

    如上證實ssh工具已安裝。如未安裝則使用yum或apt-get安裝ssh:github

sudo yum -y install openssh-server openssh-clients
sudo apt-git install ssh

    確保安裝ssh後執行以下命令生成RSA:shell

[yu@yu learn]$ ssh-keygen -t rsa -C "my_email@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yu/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/yu/.ssh/id_rsa.
Your public key has been saved in /home/yu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:hAIHR1Cc2hQo4GqcTI0vjz+vSI9biOyJ7MAgATE63gQ 312875237@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|*E+B*o           |
|=.=++  .         |
|+= *. . .        |
|*o* .. .         |
|+B o    S        |
|B =              |
|o* o             |
|* B.             |
|oO.++.           |
+----[SHA256]-----+

    生成的RSA在用戶家目錄下的.ssh文件夾的id_rsa.pub文件中:dom

[yu@yu learn]$ cat /home/yu/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDC8lT8NWMOwPIlgXGaRpXcDuifDZ2llWLREgieBK6ncws9RawA/6vcg+wQ+GhtLARuK22GDALqAbiA66twoqa85El3Eb+nRyShm2gAOE+XwJCj9C7soMUxHREhoa4ZPrI4q8YjdRiv7j4IH+8D3J1wCYCxwCvt+YaNQ5WolmMEe6zDbzNOvCuudDZXKcpLfel9NDpRN3L5Y/xqciXS2Rgz611x3/acllm3zkVYv1LMg9Mybnos/+jIFv3dZZd2inJIEq+Qmp/4iMvO3vDu2bX3jJvlW/T+HEZeMiDIv/O4Khh3NRBOu82dcWAltcWyKOyuaHaDFqzvQaopwh37TI5P 3189109768@qq.com

    添加RSA到github

    進入github主頁登錄帳號,並進入Setting頁面。切換到SSH and GPG keys選項卡,在SSH keys區域使用New SSH key 添加SSH公鑰。ssh

    其中,Title名稱隨意,最好有明確意義;Key處輸入id_rsa.pub的內容。ide

    測試

    使用ssh命令測試ssh登錄,出現如下效果則表示登錄成功。工具

[yu@yu learn]$ ssh -T git@github.com
Hi treesYU! You've successfully authenticated, but GitHub does not provide shell access.
相關文章
相關標籤/搜索