【问题标题】:Using a non-default key name (other than id_rsa)使用非默认键名(id_rsa 除外)
【发布时间】:2017-05-15 17:48:44
【问题描述】:

我已将 Github 无密码登录设置如下。

ssh-keygen -t rsa  -P ''  
cat .ssh/id_rsa.pub  |xclip 

我将公钥粘贴到 Github 网站上的 ssh 和 gpg 密钥中。

git init  
git config --global user.name "someone"  
git config --global user.email  "sbd@gmail.com"  
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git  
ssh -T git@github.com  
git clone  git+ssh://git@github.com/someone/newstart.git   /tmp/newstart

以上工作。

现在我想为 Github 使用不同的密钥名称,而不是其默认名称 id_rsa

ssh-keygen -t rsa  -P ''  -f  .ssh/id_rsa.github
cat .ssh/id_rsa.github.pub  |xclip 

我将新的 pub 密钥粘贴到 Github 网站上的 ssh 和 gpg 密钥中。

git init  
git config --global user.name "someone"  
git config --global user.email  "sbd@gmail.com"  
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git  
ssh -T git@github.com 

上述方法无效。

git clone  git+ssh://git@github.com/someone/newstart.git   /tmp/newstart

上面的也行不通。

ssh -i .ssh/id_rsa.github -T git@github.com

上面的命令可以连接Github成功,但是我无法输入下面的命令来克隆仓库。

git clone  -i  .ssh/id_rsa.github  git+ssh://git@github.com/someone/newstart.git   /tmp/newstart

我不能使用其他名称(例如 id_rsa.github)而不是默认名称 id_rsa 的 pub 密钥吗?

【问题讨论】:

    标签: git github ssh


    【解决方案1】:

    您需要告诉 SSH 将此密钥用于 Github。把这个放在~/.ssh/config:

    Host github.com
        IdentityFile ~/.ssh/id_rsa.github
        User git
    

    【讨论】:

    • 这工作谢谢!奇怪的是 GitHub 没有从 ssh 配置文件中获取 Hostname 指令(它们只使用上面举例说明的 Host 指令),而 Bitbucket.org(或 bitbucket.com)使用 Host bitbucket \nHostName bitbucket.orgform。
    猜你喜欢
    • 2021-03-13
    • 2018-09-02
    • 2023-03-31
    • 1970-01-01
    • 2014-06-25
    • 2018-09-15
    • 1970-01-01
    • 2014-08-08
    • 2011-06-14
    相关资源
    最近更新 更多