I know about RSA authentication, but for my purposes I want to use heredoc to specify a password. I want something like the following, but I cannot get it to work. Is it possible?
#!/bin/bash echo -n "Enter Password: " read -s password ssh myhost << EOL $password echo "I'm logged onto myhost" EOL echo done
This is what I get when I try:
$ ./testssh Enter Password: Pseudo-terminal will not be allocated because stdin is not a terminal. user@myhost password: Warning: No xauth data; using fake authentication data for X11 forwarding. Warning: no access to tty (Bad file descriptor). Thus no job control in this shell. mypassword: Command not found. I'm logged onto myhost done
EDIT:
Based on bmargulies answer, I reworked my script and came up with the following:
#!/bin/bash echo -n "Enter the Host: " read HOST echo -n "Enter Username: " read USER echo -n "Enter Password: " read -s PASS VAR=$(expect -c " spawn ssh $USER@$HOST expect \"password:\" send \"$PASS\r\" expect \">\" send \"ls\r\" send \"echo 'I\'m on $HOST'\r\" expect -re \"stuff\" send \"logout\" ") echo -e "\n\n\n========" echo VAR = "$VAR" echo done
bash heredoc ssh expect
B Johnson Sep 26 '10 at 2:18 2010-09-26 02:18
source share