首页 > 技术文章 > 连接远程主机

George1994 2017-10-15 19:04 原文

连接远程主机

做法:通过ssh来连接远程主机,然后通过expect来发送密码,登陆主机以后再发送需要执行的命令来设置ss。为了避免出现超时,所以需要设置一个超时时间;

代码如下:

#!/usr/bin/expect
set user root
set host yourip
set password yourpass
spawn ssh $user@$host
set timeout 20
expect "*assword:*"
set timeout 20
send "$password\r"
expect "root@vultr:"
send "ssserver -c /etc/shadowsocks.json\r"
interact
expect eof

接下来可以设置一个别名,这样就不用每次都输入路径了, 直接输入别名即可。

alias ssh_login="shell's path"

推荐阅读