我正在尝试配置Capistrano将Node.js项目部署到我的一台服务器上。
我创建了一个ssh密钥,并将其导入github,我的服务器和我的机器(使用ssh-add
)。 ssh-add -l
列出密钥,执行ssh git@github.com
成功
-它显示github的默认消息:
嗨,我的用户名!您已成功通过身份验证,但是GitHub不提供Shell访问。
我正在运行Ruby 2.6.1 x64,Git 2.20.1 x64和Windows 10 x64(通过其他系统功能安装了OpenSSH)。
我的config/deploy.rb
文件包含以下内容:
lock "~> 3.11.0"
set :application, "myproject"
set :repo_url, "git@github.myusername/myproject.git"
set :ssh_options, { forward_agent: true, keys: 'C:/Users/myusername/mydirectory/id_rsa.pub' }
set :branch, "master"
还有config/deploy/production.rb
:
server "MYSERVERADDRESS", user: "MYSERVERUSER", roles: %w{apiServer}
set :ssh_options, { forward_agent: true, keys: 'C:/Users/myusername/mydirectory/id_rsa.pub' }
运行cap production deploy
输出以下内容:
00:00 git:wrapper
01 mkdir -p /tmp
Enter passphrase for C:/Users/myusername/mydirectory/id_rsa.pub:
MYSERVERUSER@MYSERVERADDRESS's password:
✔ 01 MYSERVERUSER@MYSERVERADDRESS 5.075s
Uploading /tmp/git-ssh-myproject-production-myusername.sh 100.0%
02 chmod 700 /tmp/git-ssh-myproject-production-myusername.sh
✔ 02 MYSERVERUSER@MYSERVERADDRESS 0.188s
00:05 git:check
01 git ls-remote git@github.com:myusername/myproject.git HEAD
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.
#<Thread:0x00000000061737b0@C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
13: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
12: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `run'
11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/tasks/git.rake:18:in `block (3 levels) in eval_rakefile'
9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:97:in `with'
8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/tasks/git.rake:19:in `block (4 levels) in eval_rakefile'
7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/git.rb:38:in `check_repo_is_reachable'
6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/git.rb:77:in `git'
5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:78:in `execute'
4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `create_command_and_execute'
3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `tap'
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `block in create_command_and_execute'
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/netssh.rb:169:in `execute_command'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/command.rb:99:in `exit_status=': git exit status: 128 (SSHKit::Command::Failed)
git stdout: Nothing written
git stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as MYSERVERUSER@MYSERVERADDRESS: git exit status: 128 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
在执行git ls-remote git@github.com:myusername/myproject.git HEAD
时看起来好像失败了。奇怪的是,当我手动运行git ls-remote git@github.com:myusername/myproject.git HEAD
时,它会成功(无论我是在cmd还是git bash中进行操作,我都尝试了这两种方法。)
我也尝试过在git bash中执行cap production deploy
,但更糟糕的是,由于Capistrano希望我输入RSA密钥的密码,此操作失败,因此在输入之前先抛出Bad file descriptor (Errno::EBADF)
在cmd中运行相同命令时不会发生的任何事情:
$ cap production deploy
00:00 git:wrapper
01 mkdir -p /tmp
Enter passphrase for C:/Users/myusername/mydirectory/id_rsa.pub:#<Thread:0x0000000006049d58@C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as MYSERVERUSER@MYSERVERADDRESS: Bad file descriptor (SSHKit::Runner::ExecuteError)
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/prompt.rb:45:in `noecho': Bad file descriptor (Errno::EBADF)
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/prompt.rb:45:in `ask'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:67:in `rescue in load_data_private_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:60:in `load_data_private_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:44:in `load_private_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:232:in `block in load_identities'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:225:in `map'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:225:in `load_identities'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:117:in `each_identity'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/methods/publickey.rb:19:in `authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:85:in `block in authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `each'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh.rb:246:in `start'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/connection_pool.rb:63:in `call'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/connection_pool.rb:63:in `with'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/netssh.rb:176:in `with_ssh'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/netssh.rb:129:in `execute_command'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `block in create_command_and_execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `tap'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `create_command_and_execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:78:in `execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `run'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:116:in `read': Could not parse PKey: no start line (OpenSSL::PKey::PKeyError)
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:116:in `block in classify_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:61:in `load_data_private_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/key_factory.rb:44:in `load_private_key'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:232:in `block in load_identities'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:225:in `map'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:225:in `load_identities'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:117:in `each_identity'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/methods/publickey.rb:19:in `authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:85:in `block in authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `each'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `authenticate'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/net-ssh-5.1.0/lib/net/ssh.rb:246:in `start'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/connection_pool.rb:63:in `call'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/connection_pool.rb:63:in `with'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/netssh.rb:176:in `with_ssh'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/netssh.rb:129:in `execute_command'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `block in create_command_and_execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `tap'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:145:in `create_command_and_execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:78:in `execute'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capistrano-3.11.0/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/abstract.rb:29:in `run'
from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as MYSERVERUSER@MYSERVERADDRESS: Bad file descriptor
Caused by:
Errno::EBADF: Bad file descriptor
Caused by:
OpenSSL::PKey::PKeyError: Could not parse PKey: no start line
我是否在配置中缺少某些内容,或者Capistrano是否有问题?有什么办法可以解决这个问题?
注意:我已在所有日志和配置文件中替换了用户名,github项目名称或磁盘路径之类的数据