github添加ssh公钥

    使用git作为版本维护工具非常方便,而且一般个人用github作为远端库就够用了。而一般git连接github的方式采用ssh的方法,http的会略微慢一些。所以为了方便一般会在github设置中添加常用电脑的SSH公钥。

    生成RSA

    首先确认是否安装了ssh工具:

[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:

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

    确保安装ssh后执行如下命令生成RSA:

[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文件中:

[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公钥。

    其中,Title名称随意,最好有明确意义;Key处输入id_rsa.pub的内容。

    测试

    使用ssh命令测试ssh登陆,出现以下效果则表示登陆成功。

[yu@yu learn]$ ssh -T git@github.com
Hi treesYU! You've successfully authenticated, but GitHub does not provide shell access.

  

posted @ 2017-10-12 10:12  TREES树海  阅读(742)  评论(0编辑  收藏  举报