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


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


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


sshpass -p ‘strongPassword’ ssh user@ command_to_run


sshpass -p ‘strongPassword’ scp *.tar.gz user@



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