【问题标题】:Capistrano deployment fails when server ssh key has a passphrase当服务器 ssh 密钥具有密码时,Capistrano 部署失败
【发布时间】:2017-06-03 15:57:16
【问题描述】:

当我在远程服务器上为 ssh 密钥设置密码时,使用 Capistrano 部署失败。

但是当没有设置密码时它可以工作......

我希望能够在部署时输入密码,以便我仍然可以在服务器上使用密码。

错误:

01 mkdir -p /tmp
01 <user>@<ip> 0.183s
Uploading /tmp/git-ssh-<app>-<env>-<me>.sh 100.0%
02 chmod 700 /tmp/git-ssh-<app>-<env>-<me>.sh
02 <user>@<ip> 0.178s
git:check

01 git ls-remote --heads git@github.com:<me>/<my-repo>.git
01 Permission denied (publickey).
01 fatal: Could not read from remote repository.
01
01 Please make sure you have the correct access rights
01 and the repository exists.

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as <user>@<ip>: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

deploy.rb

lock '3.7.1'
set :application, '<app>'
set :repo_url, 'git@github.com:<me>/<app>.git'
set :user, '<user>'
set :scm_user, '<me>'
set :deploy_to, '/home/<user>/<app>'
set :scm, :git
set :branch, 'master'
append :linked_files, 'config/database.yml', 'config/secrets.yml'
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle"

deploy/production.rb

server '<ip>', user: '<user>', roles: %w{app db web}

所以我希望 Capistrano 在部署时向我询问密码,以便我的服务器可以使用它来连接 github。

这可能吗?

【问题讨论】:

标签: ssh deployment capistrano digital-ocean ssh-keys


【解决方案1】:

您可以使用 SSH 代理转发。因此无需在服务器上输入密码。

这样您只需在本地预加载您的 ssh 密钥 ssh-add keyname_rsa 并让它们自动转发到您的主机,然后根据需要从您的主机转发到 Github 服务器。

因此,您只需在本地输入一次密码,如下所示:

其余的在部署过程中“自动”发生。值得设置。

来自the docs

1.2.1 SSH 代理转发

由于我们已经设置了 SSH 代理,我们可以使用 代理转发 SSH 的功能,使此密钥代理可用于进一步跃点。在 简而言之,我们可以使用 我们自己的 ssh 密钥 从 服务器到 Github。

【讨论】:

    猜你喜欢
    • 2016-11-20
    • 2019-05-11
    • 2011-03-17
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    相关资源
    最近更新 更多