ssh tunneling

主要使用了ssh隧道技术:

经常隧道会自动断开的原因:隧道可能因为某些原因断开,例如:机器重启,长时间没有数据通信而被路由器切断等等。

OpenSSH基于安全的理由,如果用户连线到SSH Server后闲置一段时间,SSH Server会在超过特定时间后自动终止SSH连线。

保持长连接,我们需要了解这几个参数:

TCPKeepAlive yes/no for ssh and sshd

ClientAliveCountMax for sshd

ClientAliveInterval for sshd

ServerAliveCountMax for ssh

ServerAliveInterval for ssh

To enable the keep alive system-wide (root access required), edit /etc/ssh/ssh_config; to set the settings for just your user, edit ~/.ssh/config (create the file if it doesn’t exist). Insert the following:

Host *

    ServerAliveInterval 300

    ServerAliveCountMax 2

You can also make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config:

ClientAliveInterval 300

ClientAliveCountMax 2

 connection idle timeout setting


ServerAliveCountMax

Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.


The default value is 3. If, for example, ServerAliveInterval (see below) is set to 15 and ServerAliveCountMax is left at the default, if the server becomes unresponsive, ssh will disconnect after approximately 45 seconds. This option applies to protocol version 2 only; in protocol version 1 there is no mechanism to request a response from the server to the server alive messages, so disconnection is the responsibility of the TCP stack.


ServerAliveInterval

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set. This option applies to protocol version 2 only. ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.

下面是几个参数的解释:

TCPKeepAlive
             Specifies whether the system should send TCP keepalive messages
             to the other side.  If they are sent, death of the connection or
             crash of one of the machines will be properly noticed.  However,
             this means that connections will die if the route is down tem-
             porarily, and some people find it annoying.  On the other hand,
             if TCP keepalives are not sent, sessions may hang indefinitely on
             the server, leaving “ghost” users and consuming server resources.

             The default is “yes” (to send TCP keepalive messages), and the
             server will notice if the network goes down or the client host
             crashes.  This avoids infinitely hanging sessions.

             To disable TCP keepalive messages, the value should be set to
             “no”.
 ClientAliveCountMax
             Sets the number of client alive messages (see below) which may be
             sent without sshd(8) receiving any messages back from the client.
             If this threshold is reached while client alive messages are
             being sent, sshd will disconnect the client, terminating the ses-
             sion.  It is important to note that the use of client alive mes-
             sages is very different from TCPKeepAlive (below).  The client
             alive messages are sent through the encrypted channel and there-
             fore will not be spoofable.  The TCP keepalive option enabled by
             TCPKeepAlive is spoofable.  The client alive mechanism is valu-
             able when the client or server depend on knowing when a connec-
             tion has become inactive.

             The default value is 3.  If ClientAliveInterval (see below) is
             set to 15, and ClientAliveCountMax is left at the default, unre-
             sponsive SSH clients will be disconnected after approximately 45
             seconds.  This option applies to protocol version 2 only.
 ClientAliveInterval
             Sets a timeout interval in seconds after which if no data has
             been received from the client, sshd(8) will send a message
             through the encrypted channel to request a response from the
             client.  The default is 0, indicating that these messages will
             not be sent to the client.  This option applies to protocol ver-
             sion 2 only.
 ServerAliveInterval
             Sets a timeout interval in seconds after which if no data has
             been received from the server, ssh(1) will send a message through
             the encrypted channel to request a response from the server.  The
             default is 0, indicating that these messages will not be sent to
             the server.  This option applies to protocol version 2 only.
 ServerAliveCountMax
             Sets the number of server alive messages (see below) which may be
             sent without ssh(1) receiving any messages back from the server.
             If this threshold is reached while server alive messages are
             being sent, ssh will disconnect from the server, terminating the
             session.  It is important to note that the use of server alive
             messages is very different from TCPKeepAlive (below).  The server
             alive messages are sent through the encrypted channel and there-
             fore will not be spoofable.  The TCP keepalive option enabled by
             TCPKeepAlive is spoofable.  The server alive mechanism is valu-
             able when the client or server depend on knowing when a connec-
             tion has become inactive.

             The default value is 3.  If, for example, ServerAliveInterval
             (see below) is set to 15 and ServerAliveCountMax is left at the
             default, if the server becomes unresponsive, ssh will disconnect
             after approximately 45 seconds.  This option applies to protocol
             version 2 only.


#!/bin/bash


###################################################################################

#date:2016-12-20                                                             ######

#author:victor                                                               ######

#description:                                                                ######

#this shell script is for improving the network performance to www.google.com######

###################################################################################

Ssh_Pid=`ps aux | grep '192.168.1.53'| grep -v 'grep'| awk '{print $2}'`

kill $Ssh_Pid

ssh -f -w 0:0 192.168.1.53 true

ifconfig tun0 192.168.100.2 netmask 255.255.255.252

ssh root@192.168.1.53 "ifconfig tun0 192.168.100.1 netmask 255.255.255.252"


route add -host 192.168.1.53 dev eth0

route del -net 0.0.0.0

route add -net 0.0.0.0 dev tun0















本文转自chenzudao51CTO博客,原文链接:http://blog.51cto.com/victor2016/1884527 ,如需转载请自行联系原作者




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 关于Redis使用SSH服务不可用的问题,可能由于以下原因导致: 1. SSH服务未开启:请确保SSH服务已正确开启,并且在Redis配置文件中指定正确的SSH端口号。 2. 防火墙或网络问题:请检查防火墙设置,确保SSH端口已正确开放。还要确保网络连接正常,可以尝试使用telnet命令检查SSH端口是否可用。 3. SSH证书或密码错误:请确保使用正确的SSH证书或密码连接到Redis服务器。可以尝试重新生成证书或重置密码。 如果以上方法无法解决问题,请提供更多详细的错误信息和操作步骤,以便进一步诊断问题。 ### 回答2: Redis是一种内存数据库,不提供SSH服务。SSH(Secure Shell)是一种加密网络协议,用于远程登录和执行命令,常用于管理和维护远程服务器。Redis主要用于缓存数据和处理高速读写操作,它的设计目标是提供快速高效的数据访问。由于其高性能和简单的键值存储结构,Redis通常与其他应用程序一起使用,以提高系统的性能和可扩展性。 要在Redis中使用SSH服务不可行,因为Redis不支持远程登录和执行命令的功能。如果您需要访问远程服务器并执行命令,您应该使用SSH客户端工具连接到服务器,并执行相应的操作。然后,您可以通过SSH连接在命令行中使用Redis命令,对Redis服务器进行管理和操作。 另外,为了确保Redis服务器的安全性,我们建议在远程访问时使用SSH隧道(SSH tunneling)来保护数据的传输过程。SSH隧道提供了对数据传输的加密保护,可以防止数据被中间人攻击者窃听和篡改。 总结来说,Redis是一个高性能的内存数据库,不支持SSH服务。如果您需要访问Redis服务器,并执行管理操作,您应该使用SSH客户端工具连接到服务器,然后通过命令行使用Redis命令进行操作。为了保护数据的传输过程,可以使用SSH隧道来加密数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值