I need to create a script that automatically inputs a password to OpenSSH ssh
client.
Let's say I need to SSH into myname@somehost
with the password a1234b
.
I've already tried...
#~/bin/myssh.sh
ssh myname@somehost
a1234b
...but this does not work.
How can I get this functionality into a script?
First you need to install sshpass.
apt-get install sshpass
yum install sshpass
pacman -S sshpass
Example:
sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
Custom port example:
sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM:2400
Notes:
sshpass
can also read a password from a file when the -f
flag is passed.
-f
prevents the password from being visible if the ps
command is executed.