我知道 RSA 身份验证,但出于我的目的,我想使用 heredoc 来指定密码。我想要类似下面的东西,但我无法让它工作。这甚至可能吗?
#!/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