连接远程主机

连接远程主机

做法:通过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
"
expect "root@vultr:"
send "ssserver -c /etc/shadowsocks.json
"
interact
expect eof

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

alias ssh_login="shell's path"
原文地址:https://www.cnblogs.com/George1994/p/7673709.html