I'm trying to configure Capistrano to deploy my Node.js project to one of my servers.
I created an ssh key, imported it to github, my server and my machine (with ssh-add
). ssh-add -l
lists the key, executing ssh git@github.com
succeeds
- it displays github's default message:
Hi myusername! You've successfully authenticated, but GitHub does not provide shell access.
I'm running Ruby 2.6.1 x64, Git 2.20.1 x64 & Windows 10 x64 (with OpenSSH installed via additional system features).
My config/deploy.rb
file contains the following:
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"
And 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' }
Running cap production deploy
outputs the following:
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!
Which looks like it fails at the moment of executing git ls-remote git@github.com:myusername/myproject.git HEAD
. What's strange is that when I run git ls-remote git@github.com:myusername/myproject.git HEAD
manually, it succeeds (no matter if I do this in cmd or in git bash, I tried them both).
I also tried executing cap production deploy
in git bash, but it is even worse, as it fails at the moment Capistrano expects me to input the RSA key's passphrase, throwing Bad file descriptor (Errno::EBADF)
before I am able to type anything, which does not happen when running the same in 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
Am I missing something in my configuration or is this a problem with Capistrano? Is there any way I can solve this?
Note: I've substituted data like username, github project name or disk paths in the attached all logs & config files