Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ssh receive the password from stdin

How can you make SSH read the password from stdin, which it doesn't do by default?

like image 375
olamundo Avatar asked Aug 27 '09 11:08

olamundo


People also ask

Can we pass password in SSH command?

For ssh you can use sshpass : sshpass -p yourpassphrase ssh user@host .

How do I put password in SSH?

First, open a terminal and run ssh-copy-id yourservername . You'll be asked to enter your password for the server. After entering your password, you'll be able to SSH into the server without needing a password again.


1 Answers

based on this post you can do:

Create a command which open a ssh session using SSH_ASKPASS (seek SSH_ASKPASS on man ssh)

$ cat > ssh_session <<EOF export SSH_ASKPASS="/path/to/script_returning_pass" setsid ssh "your_user"@"your_host" EOF 

NOTE: To avoid ssh to try to ask on tty we use setsid

Create a script which returns your password (note echo "echo)

$ echo "echo your_ssh_password" > /path/to/script_returning_pass 

Make them executable

$ chmod +x ssh_session $ chmod +x /path/to/script_returning_pass 

try it

$ ./ssh_session 

Keep in mind that ssh stands for secure shell, and if you store your user, host and password in plain text files you are misleading the tool an creating a possible security gap

like image 107
albfan Avatar answered Oct 28 '22 23:10

albfan