~/.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
在本地机器上:
$ 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.
笔记:
- ssh-add -l 显示所有提到的键
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 密钥之间产生的冲突引起的用来。
如果我的假设是正确的,有人可以帮我解决这个问题吗?代理转发时是否可以使用特定的用户配置?如果没有,那么解决这个问题的方法是什么?
谢谢。