Automate SCP without prompting for password

Problem : I needed to transfer files between to servers on an automated basis. In normal scp, it would prompt for a password and would not allow for automation.

Solution : Add the RSA public key of the sender on the .ssh folder of the receiver.

Steps :

1) On the sender :

mkdir -p ~/.ssh
ssh-keygen -t rsa
ssh-keygen generates, manages and converts authentication keys for ssh(1). ssh-keygen can create RSA keys for use by SSH protocol version 1 and DSA, ECDSA or RSA keys for use by SSH protocol version 2. 
This should result in two files, ~/.ssh/id_dsa (private key) and ~/.ssh/id_dsa.pub (public key).

2) Copy ~/.ssh/id_rsa.pub (public key) to the receiver on the same directory.

scp ~/.ssh/id_rsa.pub user@receiver:~/.ssh/id_rsa.pub

3) Try ssh or scp from the sender to the receiver.

Known Assumption :

The same user has a login on both the sender and the receiver using a single sign-on server.

References :

1) ssh-keygen manpages

2) Extended tutorial 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: