projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Linux Tip: SSH via BASH script using password

linuxtip

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.

Source: http://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/

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 server.example.com with password called t@uyM59bQ:
$ sshpass -p 't@uyM59bQ' ssh username@server.example.com
Under shell script you may need to disable host key checking:
$ sshpass -p 't@uyM59bQ' ssh -o StrictHostKeyChecking=no username@server.example.com

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" server.example.com:/var/www/html/ /backup/

Further readings:

Advertisements

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

Information

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