Just another site

How to set password less SSH/SCP between two Linux Hosts

First step to set up password less ssh/SCP between two Linux hosts is to generate a public/private key pair.


If you’re not familiar with public key cryptography, here’s the short explanation.



  • In public key cryptography, you generate a pair of mathematically related keys, one public and one private. 
  • You then give your public key to anyone and everyone in the world, but you never ever give out your private key. 
  • The magic is in the mathematical makeup of the keys; anyone with your public key can use it to encrypt a message, but only you can decrypt it with your private key. 



The syntax to create the key pair is:

ssh-keygen -t rsa

In response, you should see:

Generating public/private rsa key pair

Enter file in which to save the key … 

Press Enter to accept this.

In response, you should see:

Enter pass phrase (empty for no passphrase):

You don’t need a pass phrase, so press Enter twice.

In response, you should see:

Your identification has been saved in … 

Your public key has been saved in … 


Note the name and location of the public key just generated. It always ends in .pub.

Copy the public key just generated to your remote Linux box. You can use scp or FTP or whatever to make the copy.

If you are logging in as a user, for example, oracle, it would be in /home/oracle/authorized_keys.


Notice that the authorized_keys file can contain keys from other computers/servers. So, if the file already exists and contains text, you need to append the contents of your public key file to what already is there.


Now, with a little luck, you should be able to scp a file to the remote box without needing to use a password. So let’s test it by trying our first example again. Copy a file named xyz.tgz from your local PC to the /tmp dir of a remote PC called srv1:


scp xyz.tgz oracle@srv1:/tmp


Post Navigation