美文网首页
| 为 gitee/github 生成/添加 SSH 公钥

| 为 gitee/github 生成/添加 SSH 公钥

作者: Hemingway_AT | 来源:发表于2020-02-23 10:13 被阅读0次

    之前单独为 gitee 添加 SSH 公钥

    关联文件 | 码云 gitee

    【增】为 github 添加 SSH 公钥

    切到 ~/.ssh目录下,欲执行以下官方演示命令,将在 .ssh 目录下默认生成 id_rsa文件。

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    

    可以预见会与 gitee 那一套有冲突。

    • 因此,对之前 gitee 生成公钥时的关联文件进行重命名
    mv id_rsa id_rsa_gitee
    mv id_rsa.pub id_rsa_gitee.pub
    
    • 为 github 生成 SSH 公钥并指定命名
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f "id_rsa_github"
    
    关联文件 | GitHub
    • 将账户添加密钥,内容为id_rsa_github.pub中的字符

    拷贝到剪切板的命令如下:

    # Mac
    $ pbcopy < ~/.ssh/id_rsa.pub
    # Copies the contents of the id_rsa.pub file to your clipboard
    
    # Windows
    $ clip < ~/.ssh/id_rsa.pub
    # Copies the contents of the id_rsa.pub file to your clipboard
    
    # Linux
    $ sudo apt-get install xclip
    # Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
    
    $ xclip -sel clip < ~/.ssh/id_rsa.pub
    # Copies the contents of the id_rsa.pub file to your clipboard
    
    • 进行连接测试,结果发生了意外:Permission denied(出现原因:多个git环境下,使用了自定义的秘钥名称)
    ssh -T git@github.com
    
    failure :(

    解决方案:新建 config 文件,进行配置,如下

    # gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitee
    
    # github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
    

    再次进行连接测试,就好了!

    success :)

    参考

    相关文章

      网友评论

          本文标题:| 为 gitee/github 生成/添加 SSH 公钥

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