git - 使用远程主机 gitlab 从 Windows 部署 capifony 时权限被拒绝(公钥)

标签 git ssh gitlab ssh-keys capifony

我正在尝试使用 capifony 通过 gitlab 从我的本地 Windows 计算机设置部署到我的服务器。

通常我会通过 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  

最佳答案

this issue 中所述,一个可能的原因是:

My problem was that I needed to enclose my ssh key file location in quotes in my config/deploy.rb file, like this:

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

instead of:

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

还有:

I got this error even when I dont set ssh_options[:keys] in my deploy.rb.

或者:

This problem may be caused by ssh private key with passphrase and no ssh public key.

(也在 issues/101 中提到)

Try remove ssh_options[:keys] and invoke the following command:

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

这导致:

I launched ProcessMonitor and found ruby process trying to load file ~.ssh\key.pub.pub which gave me an idea that path to the private (not public) key should be in ssh_config['keys'].

So this should work:

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

另请阅读 ArgumentError: Could not parse PKey: no start line

关于git - 使用远程主机 gitlab 从 Windows 部署 capifony 时权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31751669/

相关文章:

Git 很慢

git - 如何在git中找到分支的起源?

java - 我的 JSch session 不执行命令

Gitlab CI - 启动 Shared Runner 进行正常 repo

gitlab - 如何使 gitlab 激活的特定运行器工作?

testing - 在 gitlab CI 中运行 testcafe 失败

git - git-pull 如何与 git-fetch 结合使用(是 : what does git-pull option `-p` mean)?

git - 在 Git 中切换远程分支

python - 使用未安装的模块通过 ssh 运行远程 python 代码

python - 如何在 pysftp 中定义凭据的字符集?