美文网首页
Github添加SSH Key

Github添加SSH Key

作者: Andy周 | 来源:发表于2016-07-26 23:38 被阅读116次

    原CSDN地址
    http://blog.csdn.net/byhook/article/details/50136075

    笔者操作系统是ubuntu 14.04
    运行下面的命令创建SSH Key

    ssh-keygen -t rsa -C "byhook@163.com"
    

    邮箱为github登陆邮箱
    然后根据提示输入github密码

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/byhook/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/byhook/.ssh/id_rsa.
    Your public key has been saved in /home/byhook/.ssh/id_rsa.pub.
    The key fingerprint is:
    f5:9a:53:d3:97:d1:61:11:81:f6:9a:53:e1:c2:ab:62 byhook@163.com
    The key's randomart image is:
    +--[ RSA 2048]----+
    |              .*+|
    |             o..o|
    |          . o o.o|
    |         . . + +o|
    |        S   + B..|
    |           + * . |
    |          + . .  |
    |         E o     |
    |        . .      |
    +-----------------+
    

    生成的id_rsa文件是私有密钥
    id_rsa.pub是公开的密钥
    查看公钥的内容

    cat ~/.ssh/id_rsa.pub
    

    输出结果

    ssh-rsa 公钥内容 byhook@163.com
    

    复制上述的内容

    使用私钥和github进行认证

    ssh -T git@github.com
    

    结果显示

    The authenticity of host 'github.com (192.30.252.131)' can't be established.
    RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
    Hi byhook! You've successfully authenticated, but GitHub does not provide shell access.
    

    成功!!!

    如果出现下图问题

    Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
    Agent admitted failure to sign using the key.
    Permission denied (publickey).
    

    输入命令

    ssh-add
    

    输入密码
    继续即可
    使用SSH Key访问github


    输入命令

    git remote set-url origin git@github.com:byhook/IPCSample.git
    

    OK

    以后操作都不用输入密码了

    开源中国
    http://git.oschina.net
    原理相同

    相关文章

      网友评论

          本文标题:Github添加SSH Key

          本文链接:https://www.haomeiwen.com/subject/kecojttx.html