zoukankan      html  css  js  c++  java
  • ssh的tunnel设置+autossh设置

    tunnel设置


    一、说明

    用于通过ssh转发数据


    二、设置

    编辑ssh server的'2Fetc/ssh/sshd_config

    加入下面:

    #反向遂道
    GatewayPorts  yes
    #正向遂道,注:该设翮会断开ssh的22断开

    AllowTcpForwarding true


    三、重新启动ssh

    sudo /etc/init.d/ssh restart 或 sudo service ssh restart


    四、实例

    A地址:10.1.1.1

    B地址:10.1.1.2

    1.反向遂道

    在B机器上执行

    ssh -R 8001:10.1.1.2:8002  root@10.1.1.1 -f -g -N -C -o TCPKeepAlive=yes

    效果为訪问10.1.1.1:8001 ==> 10.1.1.2:8002

    2.正向遂道

    在A机器上执行

    ssh -L 8001:10.1.1.1:8002  root@10.1.1.2 -f -g -N -C -o TCPKeepAlive=yes

    效果为訪问10.1.1.1:8001 ==> 10.1.1.2:8002


    注:因为以上方法长时间执行可能会断开连接,因此推荐下面方法
    

    autossh设置


    一、说明

    autossh 是一款开源工具。能够帮助管理SSH会话、自己主动重连和停止转发流量。


    二、安装
    sudo apt-get install autossh


    三、实例

    1.可替换ssh方式:

    autossh -M 5678 -R 8001:10.1.1.2:8002  root@10.1.1.1 -f -g -N -C

    2.开机自执行

    辑/etc/rc.local文件,加入:

    /usr/lib/autossh/autossh -M 5678 -fgNCR 8001:10.1.1.2:8002  root@10.1.1.1 

    如以xxx用户执行:

    /bin/su - xxx -c "/usr/lib/autossh/autossh-M 5678-fgNCR 8001:10.1.1.2:8002  root@10.1.1.1"


    作者測试环境说明:

    系统: ubuntu 14.04 LTS

    ssh版本号: 6.6.1p1

    autossh版本号: 1.4c


    ssh參数详细參考ssh命令+免password登入

  • 相关阅读:
    linux
    ansible
    语法糖
    jupyter login
    hadoop patch
    ganglia
    unixbench安装使用
    linux使用FIO测试磁盘的iops
    cpu事实负载使用top命令
    phoronix-test-suite测试云服务器
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7105041.html
Copyright © 2011-2022 走看看