Ubuntu使用Spawn和expect实现ssh自动登陆

2018-02-07  本文已影响194人  DiligentLeo

1.安装expect

 ls /usr/bin | grep expect 
如果显示为空,则使用以下命令安装

sudo apt-get install tcl tk expect

2. 制作自动登陆脚本

touch www.test.com
chmod +x www.test.com
vi www.test.com
#!/usr/bin/expect
spawn ssh yourusername@www.test.com
expect "*password:"
send "yourpassword\r"
expect "*#"
interact
按esc退出插入模式,然后输入:wq,保存并退出。

3.使用脚本自动登陆

cd ~ 
./www.test.com
上一篇 下一篇

猜你喜欢

热点阅读