Specifying SSH key using :ssh_flags
Closed this issue · 2 comments
lukemorton commented
I have created two rake tasks rake a
and rake b
. They both aim to run whoami
on a remote machine.
require 'remote_task'
set :user, 'staging'
set :domain, 'staging.example.com'
set :ssh_key, "private/keys/#{user}@#{domain}"
set :ssh_flags, ["-i #{ssh_key}"]
task :a do
sh "ssh -i #{ssh_key} #{user}@#{domain} whoami"
end
remote_task :b do
run 'whoami'
end
rake a
runs as expected and returns the remote user. rake b
gives me the following warning:
Warning: Identity file private/keys/staging@staging.example.com not accessible: No such file or directory.
Just wondering if there is anything I'm missing here or whether this is a known problem?
Running ssh-add
resolves the issue but I want to make the process easier on developers by using a key in the repo.
zenspider commented
If I had to guess, set :ssh_flags, ["-i #{ssh_key}"]
needs to be:
set :ssh_flags, ["-i", ssh_key]
Can you try that out?
lukemorton commented
Thanks, that worked along with specifying the user in :domain
:
require 'remote_task'
set :domain, "staging@staging.example.com"
set :ssh_key, "private/keys/#{domain}"
set :ssh_flags, ["-i", ssh_key]
task :a do
sh "ssh -i #{ssh_key} #{domain} whoami"
end
remote_task :b do
run 'whoami'
end