1.
目标服务 A
公网服务器B
访问者 C
2.
目标服务A 反向代理 公网服务器 B
公网服务器B 正向代理 目标服务 A
3.
目标A执行
a)复制公钥到服务器B 实现免密登陆
ssh-copy-id Buser@BAddress
b) 执行反向代理
autossh -M 0 -fCNR <port>:localhost:22 -o ServerAliveInterval=60 <Buser>@<BAddress> -p <Bport> -i <A_私钥>
c)查看是否成功
netstat -tnl | grep 127.0.0.1
127.0.0.1:<port>
4.执行正向代理
公网服务器B
ssh -fCNL *:<外部请求port>:localhost:<port> localhost
5.访问者C
a) 免登陆设置
ssh-copy-id Buser@BAddress
b) 配置 .ssh/config
Host <hostAlias>
HostName <BAddress>
User <Auser>
Port <外部请求port>
PreferredAuthentications publickey
IdentityFile <A_私钥>
c) 测试 ssh -vT <hostAlias>
d) 访问 ssh <hostAlias>