的〜/ .ssh /配置
# User_A
Host github.com-User_A
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# User_B
Host github.com-User_B
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user_b
IdentitiesOnly yes
# http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
Host example.com
IdentityFile ~/.ssh_keys/example_env.pem
ForwardAgent yes
在本地计算机上:
$ ssh -T git@github.com
Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
在远程计算机上
~$ ssh remote_user@example.com
[remote_user@example ~]$ ssh -T git@github.com
Hi User_A! You've successfully authenticated, but GitHub does not provide shell access.
注意:
deploy.rb包含:
set :repository, "git@User_B:<REPO_NAME>"
ssh_options[:forward_agent] = true
我正在尝试使用Capistrano将我的应用程序部署到Amazon EC2实例,我已经使用ssh-add将.pem文件添加到我的本地计算机,并且可以看到 ssh-add的输出中已登记-l 。但是在部署时我遇到了以下错误:
** [example.com :: err] ERROR: Repository not found.
** fatal: The remote end hung up unexpectedly
以下是我的cap deploy命令的完整输出:
$ cap bat deploy
triggering load callbacks
* executing `bat'
triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@User_B:<REPO_NAME> <BRANCH_NAME>"
command finished in 6296ms
* executing "if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q git@User_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi"
servers: ["example.com"]
[example.com] executing command
** [example.com :: err] ERROR: Repository not found.
** fatal: The remote end hung up unexpectedly
command finished in 3811ms
*** [deploy:update_code] rolling back
* executing "rm -rf /srv/<APP_NAME>/releases/20130723222237; true"
servers: ["example.com"]
[example.com] executing command
command finished in 477ms
failed: "sh -c 'if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q git@User_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi'" on example.com
所以我猜这个错误是由于多个SSH密钥被检测到之间的冲突引起的,即在本地机器上User_B(谁是存储库的成员)被用作默认设置但是在远程机器User_A(无法访问使用存储库。
如果我的假设是正确的,有人可以帮助我解决这个问题吗?有没有什么方法可以在代理转发时使用特定的用户配置?如果不是那么可能是什么解决方案?
感谢。
答案 0 :(得分:0)
好吧,似乎〜/ .ssh / config中列出键的顺序很重要。
最初是
# User_A
Host github.com-User_A
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# User_B
Host github.com-User_B
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user_b
IdentitiesOnly yes
# http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
Host example.com
IdentityFile ~/.ssh_keys/example_env.pem
ForwardAgent yes
之后我做了这个:
# User_B
Host github.com-User_B
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_user_b
IdentitiesOnly yes
# User_A
Host github.com-User_A
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods
Host example.com
IdentityFile ~/.ssh_keys/example_env.pem
ForwardAgent yes
但在这之后我没有重新启动机器,因此更改没有生效。
今天早上我在发布上述问题后启动机器后发现它正在运行:
在本地计算机上:
$ ssh -T git@github.com
Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
在远程计算机上
$ ssh -T git@github.com
Hi User_B! You've successfully authenticated, but GitHub does not provide shell access.
希望这有助于其他人,以防他面临类似的问题。
感谢。