Mac下使用可执行脚本记录远程服务器账号和密码

安装工具
brew install expect
brew install spawn-fcgi 
编写可执行脚本 例如~/.wiwide_dev.sh

#!/usr/bin/expect
set user root
set ipaddress 120.76.xx.xx
set passwd xxx
set timeout 30

spawn ssh $user@$ipaddress
expect {
"*password:" { send "$passwd\r" }
"yes/no" { send "yes\r";exp_continue }
}
#解决vim展示错乱问题
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
interact

 
执行
expect login.sh
 
给命令起别名
vim ~/.bash_profile
添加别名
alias wiwide_dev='expect ~/.wiwide_dev.sh' #注意:等号后面不要留空格
重新读区配置文件
source ~/.bash_profile
查看别名设置
alias
 
如果查到你设置的别名 说明已经生效 可利用别名进行登录服务器
 
如下是我登录的截图

 

mac ssh空闲时断开  在客户端设置:
  sudo vim /etc/ssh/ssh_config
    添加服务器的通信间隔 ServerAliveInterval 60 
  重启ssh服务   

posted @ 2019-02-14 14:43  arthur豆  阅读(780)  评论(0编辑  收藏  举报