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