How to pass a password to scp or ssh in a script

Problem

  • You want to use scp or ssh in a script but you can pass the password in the call

Solution

If you want to use ssh or scp in a script they ask for a password which you can not supply while running automatically. For this specific problem i use sshpass. This that you can easily provide the password.

Install (for Ubuntu/Debian)

sudo apt-get install sshpass

SSH

sshpass -p ‘strongPassword’ ssh user@192.168.2.77 command_to_run

SCP

sshpass -p ‘strongPassword’ scp *.tar.gz user@192.168.2.77:/home/user

Fin

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