Linux:外网连接服务器
Release1.0
step 01 ssh 连接公网服务器
ip 47.95.233.183: 22 default port 22
username root
password *********
step 02 反向连接内网
ssh wvdon@localhost -p1234
username :wvdon port 1234
Are you sure you want to continue connecting (yes/no)? yes
password
*******
Release2.0
解决经常中断问题
Step 01 (同上)
Step 02
ssh wvdon@localhost -p 22001
password
******
增加了监听端口,来达到连接稳定
方法
内网 a
外网 b
a内网主机添加秘钥实现免登陆
ssh-keygen -t rsa -C "mail@wvdon.com"
a添加到公网主机
ssh-copy-id b@111.123.123.123
b公网主机添加监听
sudo vi /etc/ssh/sshd_config
b添加
GatewayPorts yes
b重启ssdh
sudo service sshd restart
a安装autossh
sudo apt-get install autossh
a开启autossh
autossh -M 22002 -NfR 0.0.0.0:22001:localhost:22 root@47.95.233.183
同时到阿里云服务器安全规则配置里面添加22001,22002端口
b连接
ssh wvdon@47.95.233.183 -p 22001
a设置开机自启
sudo vi /etc/rc.local
a添加代码
autossh -M 22002 -NfR 0.0.0.0:22001:localhost:22 root@47.95.233.183
启
sudo vi /etc/rc.local
a添加代码
autossh -M 22002 -NfR 0.0.0.0:22001:localhost:22 root@47.95.233.183