侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Linux通过expect配置自动登录

2023-10-01 星期日 / 0 评论 / 0 点赞 / 47 阅读 / 1211 字

在home目录下创建.expect目录,并添加两个文件: expect登陆脚本ssh-login.exp #!/usr/bin/expect -fset timeout 30set host [

home目录下创建.expect目录,并添加两个文件:

  1. expect登陆脚本ssh-login.exp
#!/usr/bin/expect -fset timeout 30set host [lindex $argv 0]set port [lindex $argv 1]set user [lindex $argv 2]set password [lindex $argv 3]spawn ssh -p $port $user@$hostexpect {    "yes/no" { send "yes/r"; exp_continue }    "password:" { send "$password/r" }}interact
  1. expect配置脚本ssh-login.sh
# alias ssh-name="./expect/ssh-login.exp host port username password"alias ssh-n1.cluster=".expect/ssh-login.exp 192.168.9.181 22 root cluster"alias ssh-n2.cluster=".expect/ssh-login.exp 192.168.9.182 22 root cluster"alias ssh-n3.cluster=".expect/ssh-login.exp 192.168.9.183 22 root cluster"alias ssh-n4.cluster=".expect/ssh-login.exp 192.168.9.184 22 root cluster"alias ssh-n5.cluster=".expect/ssh-login.exp 192.168.9.185 22 root cluster"

.bashrc下添加

if [ -f ~/.expect/ssh-login.sh ]; then    . ~/.expect/ssh-login.shfi

广告 广告

评论区