Linux SSH without password

 

Whenever we login into remote server with ssh, it requires password authentication.

Let’s try to ssh check that you can ssh to the local host.

$ ssh localhost

By default it should ask for password.

To login without password we need to generate ssh keys, to generate use following command:

$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

Above command will create 2 files id_dsa, and id_dsa.pub in .ssh directory which is located in home directory.

Now copy id_dsa.pub to authorized_keys.

$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

Then try to ssh to your local host, it shouldn’t ask for password.

Similarly to login into a remote server copy id_dsa.pub content into remote server ~/.ssh/authorized_key file. Use following command to copy.

$ cat id_dsa.pub | ssh user@serverName/IP 'cat >> .ssh/authorized_keys'

Some recent version’s of ssh requires following permissions and authorized_keys2:

  • Put the public key in .ssh/authorized_keys2 
    • $ cp .ssh/authorized_keys .ssh/authorized_keys2
  • Change permission of .ssh directory to 700
    • $ chmod 700 .ssh
  • Change permission of .ssh/authorized_keys2 to 640
    • $ chmod 640 .ssh/authorized_keys2

-Sany

One comment on “Linux SSH without password

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 )

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