Yog*_*dav 9 git ssh openssh ssh-agent gitlab
OS Description: Ubuntu 14.04.3 LTS
ssh: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3, OpenSSL 1.0.1f 6 Jan 2014
Run Code Online (Sandbox Code Playgroud)
我无法为gitlab使用多个ssh密钥.我得到的错误是
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我非常确定我做的一切都是正确的这是我的配置文件
Host work gitlab.com
Hostname gitlab.com
IdentityFile ~/.ssh/ida_rsa
User git
Host integrate gitlab.com
Hostname gitlab.com
IdentityFile ~/.ssh/ida_rsa_personal
User git
Run Code Online (Sandbox Code Playgroud)
密钥在ssh-agent中自动添加,但为了确保我还手动添加了密钥
$ ssh-add -l
2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)
2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)
Run Code Online (Sandbox Code Playgroud)
我的ssh-agent也在运行
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-uTC6tA5HMt1x/agent.4899; export SSH_AUTH_SOCK;
SSH_AGENT_PID=4900; export SSH_AGENT_PID;
echo Agent pid 4900;
Run Code Online (Sandbox Code Playgroud)
ssh密钥的权限
-rw------- 1 yogi yogi 1679 jun 25 15:38 id_rsa
-rw------- 1 yogi yogi 1679 ago 25 10:53 id_rsa_personal
-rw-r--r-- 1 yogi yogi 404 ago 25 10:53 id_rsa_personal.pub
-rw-r--r-- 1 yogi yogi 391 jun 25 15:41 id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
我在gitlab上添加了我的ssh公钥.
有谁可以告诉我我错过了什么?
注意: - 我注意到在我的两个ssh键中,顶部的ssh键(id_rsa - e7:08 ....)工作正常.
$ ssh-add -l
**2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)**
2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)
Run Code Online (Sandbox Code Playgroud)
如果我在id_rsa之后添加id_rsa_personal(ff:22 ..),则id_rsa_personal开始正常工作并且id_rsa停止工作.
$ ssh-add -l
**2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)**
2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)
Run Code Online (Sandbox Code Playgroud)
我认为,ssh-agent无法遍历密钥.它只读取第一个键并停止.这是openssh中的一个错误吗?如果是,任何解决方法?
谢谢
Zan*_*tsu 10
你需要有~/.ssh/config文件
内部文件
# Default GitHub user
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/personalid
# Work user account
Host bitbucket.org
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/workid
Run Code Online (Sandbox Code Playgroud)
详细信息可以在以下链接中找到 :https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html
如果域相同,请使用不同的主机
Host work.gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.work
Host home.gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.home
Run Code Online (Sandbox Code Playgroud)
清除缓存
ssh-add -D
Run Code Online (Sandbox Code Playgroud)
添加所有ssh密钥
ssh-add ~/.ssh/id_rsa.work
ssh-add ~/.ssh/id_rsa.home
Run Code Online (Sandbox Code Playgroud)
同时按照给定的那样在(.git/config)中设置你的repos'url:
url = git@work.gitlab.com:xxxxxxxxxx.git
url = git@home.gitlab.com:yyyyyyyyy.git
Run Code Online (Sandbox Code Playgroud)
如果您的ssh配置文件与我的建议一致.