在Windows上使用Capifony部署到远程主机GitLab时出现“Permission denied (publickey)”错误。

4
我正在尝试通过gitlab将我的本地Windows计算机上的部署设置到我的服务器,使用capifony。
通常我会通过ssh连接到我的服务器并从服务器运行命令 现在我想从我的本地计算机上执行它。
我已经用git从我的本地计算机将代码推送到gitlab,即我的公共密钥已经在gitlab上注册了。
但是,在这里,使用capifony却不能正常工作。 可能出了什么问题?
错误信息:
D:\Divers\Programmation\Web\foodmeup.dev>cap development deploy
 ** transaction: start
--> Updating code base with remote_cache strategy
*** [deploy:update_code] rolling back
 ** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: my_server_ip (ArgumentError: Could not parse PKey: no start line)
connection failed for: my_server_ip (ArgumentError: Could not parse PKey: no start line)

编辑:

如果我按照几篇帖子中给出的指示,在我的deploy.rb文件中添加以下选项:

ssh_options[:keys] = %w('~/.ssh/id_rsa')

或者

ssh_options[:keys] = %w('~/.ssh/id_rsa.pub')

然后我被要求输入root密码,但是我仍然遇到了错误(尽管我可以直接使用Putty通过ssh登录,并且在使用另一个用户从我的服务器运行部署时无需输入root密码):

D:\Divers\Programmation\Web\foodmeup.dev>cap preprod deploy
 ** transaction: start
--> Updating code base with remote_cache strategy
root@my_server_ip's password:
 ** [my_server_ip  :: err] Error reading response length from authentication socket.
 ** [my_server_ip  :: err] Permission denied (publickey).
 ** [my_server_ip  :: err] fatal: Could not read from remote repository.
 **
 ** Please make sure you have the correct access rights
 ** and the repository exists.
*** [deploy:update_code] rolling back
failed: "sh -c 'if [ -d /home/foodmeup.net/preprod/shared/cached-copy ]; then cd /home/foodmeup.net/preprod/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --ha
rd f52737bb09edbd968319400e2d535f467c42b04c && git clean -q -d -x -f; else git clone -q -b preprod git@gitlab.com:svassaux/foodmeup.git /home/foodmeup.net/preprod/shared/cached-copy && cd /home/foodme
up.net/preprod/shared/cached-copy && git checkout -q -b deploy f52737bb09edbd968319400e2d535f467c42b04c; fi'" on my_server_ip  

你在Windows机器上使用UNIX/Linux路径吗? - Marcos Pérez Gude
我尝试使用ssh_options[:keys] = 'C:\Users\Sébastien.ssh\id_rsa.pub',但它也不起作用... - Sébastien
2个回答

0

设置 ssh_options[:keys] = %w('~/.ssh/id_rsa'),不要设置 ssh_options[:keys] = %w('~/.ssh/id_rsa.pub')


0

此问题所述,可能的原因之一是:

我的问题在于我需要在config/deploy.rb文件中用引号括起来我的ssh密钥文件位置,像这样:

ssh_options[:keys] = %w('~/.ssh/id_rsa.pub')

改为:

ssh_options[:keys] = %w(~/.ssh/id_rsa.pub)

另外:

即使我在我的 deploy.rb 中没有设置 ssh_options[:keys] ,我仍然会遇到这个错误。

或者:

这个问题可能是由于带有密码的 ssh 私钥和没有 ssh 公钥所致。

(也在 issues/101 中提到)

尝试删除 ssh_options[:keys] 并调用以下命令:

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub

这导致:

我启动了ProcessMonitor,发现ruby进程试图加载文件~.ssh\key.pub.pub,这给了我一个想法,即私钥(而不是公钥)的路径应该在ssh_config['keys']中。

所以这应该可以工作:

ssh_options[:keys] = %w('~/.ssh/id_rsa')

另请参阅 参数错误:无法解析PKey:没有起始行


嗨,感谢你的努力总结。我已经尝试了所有方法,但还没有解决我的问题。我已经进行了编辑,也许你能理解发生了什么? - Sébastien
@Sébastien,我注意到你有两个ssh_options[:keys]:保留一个,并且只包含私钥。这正如我在我的回答中所提到的。 - VonC
当然,我写得太快了。我尝试了两种方法,但是我遇到了相同的错误:它要求输入根密码,然后就失败了。当我从服务器本身部署或通过putty连接到我的服务器时,我没有被要求输入根密码...我不明白这里缺少什么。 - Sébastien
@ Sébastien,请问您使用的帐户是否不同?这个问题可能会解释为什么在Putty测试中工作正常,但在本地会话中未找到预期位置的ssh密钥。 - VonC
我可以使用Windows命令行推送到Git,而无需定义密钥位置。 - Sébastien

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