Auto-login in SSH and SCP

SSH is secured alternative to telnet. Unlike telnet, ssh packets are transmitted encrypted.  On the same line SCP, copies files from one destination to another, securely. Source(Destination) can be over network also.

Auto-login for the telnet can be done using ‘expect’, which require expect package also a little bit knowledge of shell scripting. On the other hand, SSH provides a more cleaner approach for auto-login. Keys are exchanged(stored) between the hosts enabling auto-login.

To elaborate the steps, consider user(user1) on machine1  wants to do auto login as a user(user2) on machine2. Perform following step on the respective machine. On machine1, give the following commands

  • user1@machine1>> ssh-keygen -t rsa

The above command would generate id_rsa and in $HOME/.ssh directory(default). Transfer the generated file to machine2 , using ftp or scp.

  • user2@machine2>> cat >> .ssh/authorized_keys
  • user2@machine2>> chmod 600 .ssh/authorized_keys

Thats all, you are done.

Note : Please make sure that the home directory of the user2 is not writable by any one else (permission of 755)

now when you do a ssh to user2@machine2 from user1@machine1, you would not be asked any password. Even “SCP” would work with out any password.  As an shortcut you can define alias for the ssh for machine2 in .profile, like

alias machine2=”user2@<machine2 ip >”

and when you give machine2 on the shell, you would directly ssh to the machine2.  As an description of what is going on under the hood, private key of user1@machine1 is stored as authorized in user2@machine2. So for authorization; keys are used instead of password.

This entry was posted in Compu and tagged . Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s