Skip to main content

Shell脚本实现ssh自动登录

·1 min
Linux Linux
Rory
Author
Rory
Step by step the ladder is ascended
Table of Contents
[root@xuxing ~]#yum -y install expect
[root@xuxing ~]# cat 123
#!/bin/expect
spawn ssh [email protected]
expect "password:"
send "cisco\r"
interact
[root@xuxing ~]# chmod 777 123
[root@xuxing ~]#
[root@xuxing ~]#
[root@xuxing ~]# ./123
spawn ssh [email protected]
[email protected]'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,返回之前的终端




Comments