【问题标题】:Windows ssh agent forwarding and cap\git deploy problemsWindows ssh 代理转发和 cap\git 部署问题
【发布时间】:2019-07-12 04:06:16
【问题描述】:

Capistrano 无法通过 Windows 的 ssh 代理转发连接到 git repo (bitbucket)。

环境:

Windows 10
Ruby 2.4.4 for Windows installed
Rails 5.2.2
Cap 3.11.0
OpenSSH_for_Windows_7.7p1

可以成功 ssh 到主机和git ls-remoteclone。发出 cap deploy 或 cap 任务(如 git ls-remote)时,连接到 bitbucket 存储库失败。

git stdout: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
git stderr: Nothing written

如果使用 http 并在 URL 中设置 username:password,Capistrano 确实会连接到 bitbucket 存储库。

我已经编写了上限任务来显示 SSH_AUTH_SOCK 已设置。我玩过.ssh\config,有很多选项指向键,host * 等。

deploy.rb:

set :repo_url 设置正确。

staging.rb

set :ssh_options,
    keys: ['c:\users\mike\.ssh\key.pem'],
    forward_agent: true

.ssh\config

Host hostname
  User username
  IdentityFile ~/.ssh/key.pem
  ForwardAgent yes

服务器上的/etc/ssh/sshd.conf

AllowAgentForwarding yes

寻求下一步尝试的建议。似乎 cap 使用了错误的公钥或未能使用代理转发。我也将所有密钥添加到 bitbucket 中,但没有成功。

其他发现:

在上限部署期间监控 /var/log/secure 会产生这种情况

似乎无法连接到源计算机上的 ssh-agent。

Feb 18 23:13:15 ip-255-255-255-255 sshd[19242]: Accepted publickey for railsuser from x.x.x.x port 60682 ssh2: RSA SHA256:<has>
Feb 18 23:13:15 ip-255-255-255-255 sshd[19242]: pam_unix(sshd:session): session opened for user railsuser by (uid=0)
Feb 18 23:13:15 ip-255-255-255-255 sshd[19260]: channel 2: open failed: connect failed: could not connect to authentication agent
Feb 18 23:13:15 ip-255-255-255-255 sshd[19242]: pam_unix(sshd:session): session closed for user railsuser

【问题讨论】:

    标签: git ssh capistrano openssh


    【解决方案1】:

    Capistrano 使用 net-ssh gem,而 net-ssh 目前不支持 Windows 原生安装 OpenSSH。

    Net-ssh 确实支持Putty's pageantCygwin's ssh-agent 安装。

    我已经成功测试了 Putty 的选美,它按预期工作。

    【讨论】:

    • 要扩展上述内容,您将安装pageant.exe,不需要主要的腻子应用程序。此外,如果您要转换 ssh-2 密钥,则需要安装 puttygen.exe 并导入旧密钥,保存转换后的密钥并将其导入到 pageant。
    猜你喜欢
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    相关资源
    最近更新 更多