1.准备工作:安装expect
for Ubuntu
sudo apt-get install expect
for Centos
yum install expect
2.完整脚本
#!/usr/bin/expect
spawn /usr/bin/ssh [email protected] -p 22
expect "password:"
send "remoteComputerPassword\r"
expect efo
interact
注意事项: 如果脚本无法执行,请查看脚本是否添加了可执行权限。