Shell脚本实现ssh自动登录

[root@xuxing ~]#yum -y install expect
[root@xuxing ~]# cat 123
#!/bin/expect
spawn ssh root@10.124.45.123 
expect "password:"
send "cisco\r"
interact
[root@xuxing ~]# chmod 777 123 
[root@xuxing ~]# 
[root@xuxing ~]# 
[root@xuxing ~]# ./123
spawn ssh root@10.124.45.123
root@10.124.45.123's password: 
Last login: Fri Nov 20 04:53:03 2020 from 10.140.0.42
[root@nso ~]# 
[root@nso ~]#
四个命令的解释

send:用于向进程发送字符串
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互,如果没有该命令会直接终端session,返回之前的终端

Tags:

           

No comments

Comments feed for this article

Reply

Your email address will not be published. Required fields are marked *