SSH 内网穿透

ssh -gfnNTR x.x.x.x:222:localhost:222 root@x.x.x.x -o ServerAliveInterval=300

Note: x.x.x.x是我的ECS服务器公网IP  localhost是指ssh client自己的127.0.0.1 .

  -o ServerAliveInterval=300
    的意思是让ssh client每300秒就给server发个心跳,以免链路被RST.
  -f Requests ssh to go to background just before command execution.
    让该命令后台运行 .
  -n Redirects stdin from /dev/null (actually, prevents reading from stdin).
 
  -N Do not execute a remote command.
    不执行远程命令 .
  -T Disable pseudo-tty allocation.
    不占用 shell .
  -g Allows remote hosts to connect to local forwarded ports.
    允许非本机地址(任何公网IP)连接x.x.x.x的2333端口.{see man sshd_config(5)}.
    这个选项非常重要, 要让这个选项生效需要在x.x.x.x服务器(ssh server)上编辑/etc/ssh/sshd_config 添加一行GatewayPorts yes 然后保存退出并 service ssh restart.


整个命令这样理解: 公司机器告诉ECS说 你给我监听一下你的IP的2333端口,把这个2333端口的所有数据都发到我这的127.0.0.1的22端口.

  然后我在家里用putty设置IP为ECS的x.x.x.x 端口为2333, 顺利连上了公司的机器 ,并且ssh登录成功.


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值