1

Currently i'm doing an ssh connection in my code like this:

Net::SSH.start( @HOST, @USER, :password => @PASS ) do|ssh|
   @result = ssh.exec!("ls")
   end

Now I need to do an SSH connection without giving any password. I was not able to find the exact format to start ssh connection without giving any password.

I have added the SSH keys in authorized key list of the HOST. I remember seeing the below code somewhere on the net when i browsed for ssh without password.

Net::SSH.start( @HOST, @USER) do|ssh|
       @result = ssh.exec!("ls")
       end

Please correct me if iam wrong

1 Answer 1

2

You have to point to your private key, not public key:

@USER = "me" 
@KEYS = ["my private key here"] 
@HOST = hostname  
Net::SSH.start( @HOST, @USER, :key_data=>@KEYS, :keys_only=>TRUE ) do|ssh|
  @result = ssh.exec!("ls")                 
end 

and now it does not take the password anymore.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Question: do you know how to automatically accept the rsa host key? (the first time you log onto linux you have to type 'yes' to accept the host key that is exchanged)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.