部署出现“Authentication Failed”错误提示

4
我使用Capifony很顺利地部署了Symfony2应用程序数周,但是有一天我运行cap deploy却无法正常工作。我没有更改任何密钥或其他设置。我是从我的Bitbucket仓库进行部署。
我已经检查了所有文件的权限和所有权。
/var/git/.ssh/authorized_keys 权限为 600 用户 git
/var/git/.ssh/known_hosts 权限为 640 用户 git
/var/git/.ssh/config 权限为 700 用户 git:
Host bitbucket.org
 Hostname bitbucket.org
 ForwardAgent yes
 ForwardX11 no
 User git
 IdentityFile /var/git/.ssh/bitbucket_rsa

我可以使用相同的公钥从我的本地机器登录到生产服务器的bitbucket。我尝试了另一个密钥。

我已重新安装ruby(1.9.3)。我尝试了Capifony 2.4.2,并尝试退回到早期版本(2.4.0和Capistrano 2.15.5)。

没有解决这个问题。

在deploy.rb中:

set :repository,  "git@bitbucket.org:username/example.git"
set :scm,         :git

ssh_options[:forward_agent] = true
ssh_options[:verbose] = :debug
ssh_options[:keys] = %w(/var/git/.ssh/bitbucket_rsa)

运行 cap deploy:check 命令。
* ←[32m2014-02-04 09:20:30 executing `deploy:check'←[0m
* ←[33mexecuting "test -d /var/www/vhosts/example.com/releases"←[0m
servers: ["example.com"] D, 
[2014-02-04T09:20:30.140652 #11708] DEBUG -- net.ssh.transport.session[15bfe8c]: 
establishing connection to example.com:22
D, [2014-02-04T09:20:30.320662 #11708] DEBUG -- net.ssh.transport.session[15bfe8c]:
connection established
I, [2014-02-04T09:20:30.320662 #11708]  INFO -- net.ssh.transport.server_version 
[15bf274]: negotiating protocol version
D, [2014-02-04T09:20:30.469671 #11708] DEBUG -- net.ssh.transport.server_version
[15bf274]: remote is `SSH-2.0-OpenSSH_5.3'
D, [2014-02-04T09:20:30.470671 #11708] DEBUG -- net.ssh.transport.server_version
[15bf274]: local is `SSH-2.0-Ruby/Net::SSH_2.8.0 i386-mingw32'
D, [2014-02-04T09:20:30.530674 #11708] DEBUG -- tcpsocket[15bfb5c]: read 784 bytes
D, [2014-02-04T09:20:30.530674 #11708] DEBUG -- tcpsocket[15bfb5c]: received packet nr 
0 type 20 len 780
I, [2014-02-04T09:20:30.530674 #11708]  INFO -- net.ssh.transport.algorithms[15bb0b0]: 
got KEXINIT from server
I, [2014-02-04T09:20:30.530674 #11708]  INFO -- net.ssh.transport.algorithms[15bb0b0]: 
sending KEXINIT
D, [2014-02-04T09:20:30.531675 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
0 type 20 len 1620
D, [2014-02-04T09:20:30.531675 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 1624 bytes
I, [2014-02-04T09:20:30.531675 #11708]  INFO -- net.ssh.transport.algorithms[15bb0b0]: 
negotiating algorithms
D, [2014-02-04T09:20:30.531675 #11708] DEBUG -- net.ssh.transport.algorithms[15bb0b0]: 
negotiated:
* kex: diffie-hellman-group-exchange-sha1
* host_key: ssh-rsa
* encryption_server: aes128-cbc
* encryption_client: aes128-cbc
* hmac_client: hmac-sha1
* hmac_server: hmac-sha1
* compression_client: none
* compression_server: none
* language_client:
* language_server:
D, [2014-02-04T09:20:30.532675 #11708] DEBUG -- net.ssh.transport.algorithms[15bb0b0]: 
exchanging keys
D, [2014-02-04T09:20:30.532675 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
1 type 34 len 20
D, [2014-02-04T09:20:30.532675 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 24 bytes
D, [2014-02-04T09:20:30.652681 #11708] DEBUG -- tcpsocket[15bfb5c]: read 152 bytes
D, [2014-02-04T09:20:30.652681 #11708] DEBUG -- tcpsocket[15bfb5c]: received 
packet nr 1 type 31 len 148
D, [2014-02-04T09:20:31.893752 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
2 type 32 len 140
D, [2014-02-04T09:20:31.893752 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 144 bytes
D, [2014-02-04T09:20:31.964757 #11708] DEBUG -- tcpsocket[15bfb5c]: read 720 bytes
D, [2014-02-04T09:20:31.964757 #11708] DEBUG -- tcpsocket[15bfb5c]: received packet nr 
2 type 33 len 700
D, [2014-02-04T09:20:31.968757 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
3 type 21 len 20
D, [2014-02-04T09:20:31.968757 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 24 bytes
D, [2014-02-04T09:20:31.968757 #11708] DEBUG -- tcpsocket[15bfb5c]: received packet nr 
3 type 21 len 12
D, [2014-02-04T09:20:31.969757 #11708] DEBUG -- 
net.ssh.authentication.session[15647f4]: beginning authentication of `git'
D, [2014-02-04T09:20:31.969757 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
4 type 5 len 28
D, [2014-02-04T09:20:31.969757 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 52 bytes
D, [2014-02-04T09:20:32.129766 #11708] DEBUG -- tcpsocket[15bfb5c]: read 52 bytes
D, [2014-02-04T09:20:32.129766 #11708] DEBUG -- tcpsocket[15bfb5c]: received packet nr 
4 type 6 len 28
D, [2014-02-04T09:20:32.129766 #11708] DEBUG -- 
net.ssh.authentication.session[15647f4]: trying none
D, [2014-02-04T09:20:32.130766 #11708] DEBUG -- tcpsocket[15bfb5c]: queueing packet nr 
5 type 50 len 44
D, [2014-02-04T09:20:32.130766 #11708] DEBUG -- tcpsocket[15bfb5c]: sent 68 bytes
D, [2014-02-04T09:20:32.290775 #11708] DEBUG -- tcpsocket[15bfb5c]: read 84 bytes
D, [2014-02-04T09:20:32.290775 #11708] DEBUG -- tcpsocket[15bfb5c]: received packet nr 
5 type 51 len 60
D, [2014-02-04T09:20:32.290775 #11708] DEBUG --     
net.ssh.authentication.session[15647f4]: allowed methods: publickey,gssapi-
keyex,gssapi-with-mic,password
D, [2014-02-04T09:20:32.291775 #11708] DEBUG --     
net.ssh.authentication.methods.none[156bb14]: none failed
D, [2014-02-04T09:20:32.291775 #11708] DEBUG -- 
net.ssh.authentication.session[15647f4]: trying publickey
D, [2014-02-04T09:20:32.291775 #11708] DEBUG -- net.ssh.authentication.agent[15a9f68]: 
connecting to ssh-agent
E, [2014-02-04T09:20:32.292775 #11708] ERROR -- net.ssh.authentication.agent[15a9f68]: 
could not connect to ssh-agent
D, [2014-02-04T09:20:32.292775 #11708] DEBUG -- 
net.ssh.authentication.session[15647f4]: trying password
E, [2014-02-04T09:20:32.292775 #11708] ERROR -- 
net.ssh.authentication.session[15647f4]: all authorization methods failed (tried none, 
publickey, password)
connection failed for: example.com (Net::SSH::AuthenticationFailed: Authentication 
failed for user git@example.com)

我错过了什么?我已经疯了,试图解决这个问题。

谢谢你的帮助。


无法连接到ssh代理。 - Alister Bulman
好的,我看到了错误。解决方案是什么?ssh-agent正在运行,并且我能够使用相同的密钥从我的本地机器连接。Capistrano有什么不同? - hipnosis
4个回答

3

capistrano/capifony(更确切地说是net_ssh)尝试使用不存在的代理连接服务器,因此失败。

移除...

ssh_options[:forward_agent] = true

...并添加

ssh_options[:use_agent] = false

您没有使用代理(存储ssh可以查询的密钥的进程)连接到服务器...这意味着您无法进行转发。您提供了连接的公钥:

ssh_options[:keys] = %w(/var/git/.ssh/bitbucket_rsa)

虽然我将 forward_agent 设置为 false,但我只需要设置我的 RSA 密钥路径。 - Francisco Quintero

3

我之前也遇到了同样的问题。我通过以下步骤解决了这个问题。

 >> gem uninstall net-ssh -v 2.8.0
 >> gem install net-ssh -v 2.7.0

现在,当我调用 "cap" 方法时,它可以完美地运行并要求输入密码。


1
我原以为是forward_agent选项导致的问题,但实际可能是这个:
使用ssh-agent管理时,Bitbucket使用列表中的第一个密钥。如果仍然遇到问题,请尝试删除除要连接的标识之外的所有标识。
在此处找到: https://confluence.atlassian.com/display/BITBUCKET/Troubleshoot+SSH+Issues 我必须摆脱ssh_options[:keys] = %w(/var/git/.ssh/bitbucket_rsa),并使用已经加载的默认id_rsa而不是bitbucket_rsa。

0
我的问题是:
我没有在目标服务器的~/.ssh/authorized_keys中添加我的id_rsa.pub密钥。添加密钥后,它就可以工作了!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接