Tech, Gadgets, Photography, Social Media and Poor Spelling

Linux Tip: SSH via BASH script using password


I was looking for a way using a bash script to login to remote servers (about 30) using username and password, the proper way to do this would be using a passwordless login, however that isn’t always possible. This tip was very useful.


Install sshpass under Debian / Ubuntu Linux

Type the following command:
$ sudo apt-get install sshpass

How do I use sshpass?

Login to ssh server called with password called t@uyM59bQ:
$ sshpass -p 't@uyM59bQ' ssh
Under shell script you may need to disable host key checking:
$ sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no

How do I backup /var/www/html using rsync?

Run rsync over SSH using password authentication, passing the password on the command line:
$ rsync --rsh="sshpass -p myPassword ssh -l username" /backup/

Further readings:


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 )

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


This entry was posted on March 14, 2013 by in Linux, tip, Ubuntu and tagged , , , , , , , , , , .
%d bloggers like this: