首先创建一个expect脚本ssh_expect,文件内容如下:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#!/usr/bin/expect -f set hostname [lindex $argv 0] set user [lindex $argv 1] set passwd [lindex $argv 2] set timeout 30 set force_conservative 1 if {$force_conservative} { set send_slow {128 .1} } spawn ssh $user@$hostname; expect { "*continue connecting (yes/no)?" { send -s "yes\r"; exp_continue } "*assword:" { send -s "$passwd\r"; } } interact
然后定义一些命令别名,比如:
复制代码
1
2alias h101='ssh_expect 192.168.0.101 <user> <password>' alias h102='ssh_expect 192.168.0.102 <user> <password>'
这些别名可以写到~/.bashrc文件中
然后执行 h101 就可以自动登录192.168.0.101机器了。
最后
以上就是紧张宝贝最近收集整理的关于Linux中使用expect脚本实现远程机器自动登录的全部内容,更多相关Linux中使用expect脚本实现远程机器自动登录内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复