As you know, when you SSH into a system, it will ask for the password which you have to enter everytime. But in cases where you’re SSHing in a script or in a loop, its a really time consuming and boring thing to enter password everytime.

So, in this case you have to configure SSH to use a password to enter when asked. But, there is no default option in the ssh command to set this due to security reasons I think. Therefore we should use another way to automatically enter the password.

Fortunately, there is a program called sshpass that will enter the password automatically and logs in. All you have to do is, give the password and the normal ssh command.

You can install the sshpass command in an Ubuntu system using this :

sudo apt-get install sshpass

Yes, it’s in the official Ubuntu repository. sshpass works by fooling ssh into thinking that the password was entered by an interactive user.

The password should be given in the -p parameter and the following should be the ssh command. No separate host name should be given to sshpass. Here’s an example :

This is the normal ssh command which is used for opening firefox browser in system of IP address :

ssh [email protected] "firefox"

And this is how the above command become in sshpass assuming the password as “subin” :

sshpass -p "subin" ssh [email protected] "firefox"

You can also use sshpass to use a file to read the password and more.

Note that sshpass is its infacy at the moment and therefore bugs are highly possible. But, for me it worked like a charm. You can read the manual of sshpass here at the online man page.