I have a use case where I should enter user name and password in one command line, basically it is an automated script so I don’t want to enter the password manually so to achieve this, I tried so many things but no use
I also tried -o StrictHostKeyChecking=no and ssh-keys but no Luck
Finally I found sshpass, I think this is the only solution to achieve this use case and follow the below command
sshpass -p your_password ssh user@hostname
sshpass -p your_password ssh user@hostname <commands you want to execute on host vm>
sshpass -p “your_password” ssh user@hostname ls
sshpass -p your_password scp user@hostname:/Users/textfile .
You can download sshpass for Mac from here:
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@example.com 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 firstname.lastname@example.org "uptime"
$ sshpass -p 'PASSWORD' ssh -o StrictHostKeyChecking=no email@example.com "who"