Autossh 内网穿透

autossh 内网穿透

原理

现有如下三台服务器

服务器描述
aliyun外网服务器,默认端口都开放(CentOS)
inner内网服务器,能访问外网(CentOS)
local用户本地

大致流程:

  1. inner通过autosshaliyun建立长链接
  2. local可以访问aliyun
  3. 再由aliyun通过autossh链接访问到inner

实现

  1. inner中,安装autossh

    yum -y install autossh
    
  2. inner生成ssh公钥,并复制到aliyun

    ssh-keygen -t rsa
    ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 [aliyun用户名]@[aliyun的IP]  # root@192.168.10.111
    
  3. aliyun中配置ssh参数

    vim /etc/ssh/sshd_config # 检查如下配置是否开启
    systemctl restart sshd # 重启ssh服务
    
    GatewayPorts yes
    TCPKeepAlive yes
    ClientAliveInterval 60  
    ClientAliveCountMax 3
    
    PubkeyAuthentication yes
    AuthorizedKeysFile      .ssh/authorized_keys
    
  4. inner中调用autossh实现反向代理

    autossh -p 22 -M 9997 -fNR 9998:localhost:22 [aliyun用户名]@[aliyun的IP]
    

    将inner的22端口,映射到aliyun的9998端口

  5. local通过aliyun访问inner

    ssh -p9998 [aliyun用户名]@[aliyun的IP]
    

    在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值