iterm自动登录ssh脚本

经常在工作中需要切换到不同的服务器去部署,或者查看日志,每次登录都要去找对应的IP和地址,非常麻烦,最终决定使用iterm2+脚本来实现自动登录。

1、iterm2(下载安装不再介绍http://www.iterm2.com/downloads.html
iterm2->Perferences->Profiles
方法一:
command:expect 脚本路径
以下为脚本内容:
#!/usr/bin/expect -f
set user root
set host 10.0.0.1
set password mypassward
set timeout -1
spawn ssh $user@$host
expect "*assword:*" {send "$password\r";interact}
方法二:
编写启动脚本auto_ssh.exp放在/usr/local/bin/目录下(记得给脚本增加可执行权限),选择login shell,Send text at start 输入 auto_ssh.exp 登录名 ip 密码即可
脚本内容:
#!/usr/bin/expect
set timeout 30
spawn ssh [lindex $argv 0]@[lindex $argv 1]
expect {
"(yes/no)?"
{send "yes\n";exp_continue}
"password:"
{send "[lindex $argv 2]\n"}
}
interact
推荐使用方法二,平时也可以直接用命令行来执行,比较方便

图片上传不了,可点击链接查看:http://note.youdao.com/noteshare?id=f2ef6e23c6eed35054b0d5a699d8b32d

posted @ 2017-11-15 10:53  凌晨灵修  Views(1475)  Comments(0Edit  收藏  举报