Use SSH Client With Password On Command Line

Posted on in Categories last updated June 22, 2011

How do I pass an additional command line option to my OpenSSH client for password? I need to pass the both usename and password on the command line as follows:

ssh [email protected] myPasswordHere “command1”

How do I pass a password to ssh client under Linux or UNIX operating systems?

You need to use the sshpass command. It is a utility designed for running ssh using the mode referred to as “keyboard-interactive” password authentication, but in non-interactive mode. You can install it as follows:
$ sudo apt-get install sshpass
And pass the password as follows:
$ sshpass -p 'mySSHPasswordHere' ssh [email protected] "uptime"
OR
$ sshpass -p 'PASSWORD' ssh -o StrictHostKeyChecking=no [email protected] "who"

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment