Sunday, 21 August 2011

Connecting to remote host with ssh without password - By passing ssh/scp password

go to the node from where you will be connecting [ source machine ]
ssh-keygen -t dsa or ssh-keygen -t rsa
this will generate public and private key when asked for file name and password just press enter so that default file will be created and password will be blank

now copy the .pub content to the target machine's authorized_keys file under [username]/.ssh/

ssh-copy-id  -i [pub_file_name] [username]@[targethostname] [it will ask for password to connect to target provide password for this time]

ex: ssh-copy-id  -i testuser@testserver

this command will copy the public key to the target machines user's authorised_keys file

location of the authorized_key file is - [user's home folder]/.ssh/

if the above command does not work copy the public key manually to target machine

add the copied public key to user's authorized_key file, if it does not exist just create one

ex: ssh-copy-id -i test@testserver

Note: ssh-copy-id command sets the permission properly. if its created manually ,Make sure the autorised_key file is with 600 permission. Other wise it will keep asking password.
Ex: -rw-------. 1 yoonus yoonus 611 Feb 23 00:49 authorized_keys

now connecting with ssh/scp  should not ask for password

No comments:

Post a Comment