where to specify the public key and username in ssh command?

396 views
Skip to first unread message

Tommy Chheng

unread,
Feb 28, 2011, 9:08:22 PM2/28/11
to ruby...@googlegroups.com
I'm trying to run a series of commands via Fog's ssh method, but im unsure where to specify the public key and the username in the ssh command? 

Trying:
compute = Fog::Compute.new(:provider => "AWS", 
                             :aws_access_key_id => AWS_ID, 
                             :aws_secret_access_key => AWS_KEY)
server = compute.servers.last
server.ssh(['ls'])

thanks,
Tommy

geemus (Wesley Beary)

unread,
Mar 1, 2011, 2:15:38 PM3/1/11
to ruby...@googlegroups.com
You can add it right there, like this:
compute = Fog::Compute.new(:provider => "AWS", 
                             :aws_access_key_id => AWS_ID, 
                             :aws_secret_access_key => AWS_KEY)
server = compute.servers.last
server.username = 'username'
server.public_key_path = 'path/to/key'
server.ssh(['ls'])

or you can specify them in your ~/.fog file under the default key and it will use that.

Tommy Chheng

unread,
Mar 1, 2011, 3:12:29 PM3/1/11
to ruby...@googlegroups.com
I tried a system ssh command and it works, but server.ssh still fails:

require 'rubygems'
require 'fog'
require 'rake'
require File.join(File.expand_path(File.dirname(__FILE__)), 'install_cmds')

AWS_ID = XXX
AWS_KEY = YYYY
PUBLIC_KEY_PATH =  File.join(File.expand_path(File.dirname(__FILE__)), '..', 'ec2-keys', 'XXX.pem')
PRIVATE_KEY_PATH =  File.join(File.expand_path(File.dirname(__FILE__)), '..', 'ec2-keys', 'YYYY.pem')

compute = Fog::Compute.new(:provider => "AWS", 
                             :aws_access_key_id => AWS_ID, 
                             :aws_secret_access_key => AWS_KEY)
server = compute.servers.last
server.username = 'ubuntu'
server.public_key_path = PUBLIC_KEY_PATH

#this fails with Net::SSH::AuthenticationFailed: ubuntu
server.ssh(["ls"])

#this works
system("ssh -i #{server.public_key_path} #{server.username}@#{server.dns_name} ls")


-- 
@tommychheng

geemus (Wesley Beary)

unread,
Mar 1, 2011, 4:58:28 PM3/1/11
to ruby...@googlegroups.com
Oops, I think I told you slightly wrong. Looks like it is the private key path that really matters, not public.  Try something like this:

  server = compute.servers.last
  server.username = 'ubuntu'
  server.private_key_path = PRIVATE_KEY_PATH
Reply all
Reply to author
Forward
0 new messages