RSA認証については知っていますが、私の目的のために、ヒアドキュメントを使用してパスワードを指定したいと考えています。次のようなものが欲しいのですが、うまくいきません。これは可能ですか?
#!/bin/bash
echo -n "Enter Password: "
read -s password
ssh myhost << EOL
$password
echo "I'm logged onto myhost"
EOL
echo done
これを試してみると、次のようになります。
$ ./testssh
Enter Password:
Pseudo-terminal will not be allocated because stdin is not a terminal.
user@myhost's 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
編集:
bmargulies の回答に基づいて、スクリプトを作り直して、次のように思いつきました。
#!/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