Linux How To: How To SSH Without Password Authentication

By Angsuman Chakraborty, Gaea News Network
Sunday, May 20, 2007

Often you need to remotely run utilities on other machines through unattended batch process or cron job. ssh allows you to execute code on remote machine. However in normal usage it prompts you for password which makes it hard to use in unattended processes. Here is a simple way to eliminate the need for specifying password every time when connecting through ssh.

Let’s assume your want to connect to remote machine named remote as user named user.

You need to first, and only once, generate a private-public keypair using ssh-keygen as follows:
ssh-keygen -t dsa

This will create a private and public keypair which is stored in ~/.ssh directory.

Next run the following command once for every machine you want to remotely login without specifying password:
scp ~/.ssh/id_dsa.pub user@remote:~user/.ssh/authorized_keys

Now you can login to the machine using ssh without requiring to specify any password. Your public key, which you copied to the remote machine, is checked (not directly) against your private key to verify your authenticity.

Discussion

nagios1
June 22, 2010: 12:41 am

Dear people,
can anyone can assist me in solving the problem for ssh authentication without password? I have generated keys and placed in remote server too inside the home directory of nagios users? I have changed setting in sshd_config file in /etc/…but still i need to log into that remote server with password? My remote machine is linux and nagios server machine is centOS.

Regards,
Nagios


Eric
July 8, 2009: 8:01 pm

You’re going to overwrite any other authorized keys using scp. You need to append the new key to the auths file instead.

Something like this should work.

cat ~/.ssh/id_rsa.pub | ssh user@remote ‘cat >> ~/.ssh/authorized_keys’


Balakumar
January 16, 2009: 1:08 am

Dear Mr.Angsuman Chakraborty ,

Thank U so much for great Post

May 20, 2007: 4:11 am

Thanks for the password info. Great Post.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :