Solve the problem that the centos7 server is always automatically disconnected through ssh.

Source: Internet
Author: User
Tags openssh server

Solve the problem that the centos7 server is always automatically disconnected through ssh.

I recently bought a server and tried to connect to the server over ssh for a period of time. Now, the solution is simple.
After logging on to the server, enter lsb_release-a to view the system version. This command is applicable to all linux releases, including Redhat, SuSE, and Debian. However, you must install lsb In debian. For example:

[root@chen /]# lsb_release -aLSB Version:    :core-4.1-amd64:core-4.1-noarchDistributor ID: CentOSDescription:    CentOS Linux release 7.3.1611 (Core) Release:        7.3.1611Codename:       Core

This method is applicable to centos7. Use a text compiler to open a configuration file in the ssh service. The Code is as follows:

[root@chen /]# vi /etc/ssh/sshd_config #       $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $# This is the sshd server system-wide configuration file.  See# sshd_config(5) for more information.# This sshd was compiled with PATH=/usr/local/bin:/usr/bin# The strategy used for options in the default sshd_config shipped with# OpenSSH is to specify options with their default value where

Now you have entered the configuration file. Enter I to enter the editing mode and find the following code:

#PermitUserEnvironment no#Compression delayed#ClientAliveInterval 0#ClientAliveCountMax3#ShowPatchLevel no#PidFile /var/run/sshd.pid#MaxStartups 10:30:100#PermitTunnel no#ChrootDirectory none#VersionAddendum none

Set

#ClientAliveInterval 0#ClientAliveCountMax3

Remove the comment and change it

ClientAliveInterval 60ClientAliveCountMax 3

ClientAliveInterval specifies the time interval for the server to request messages from the client. The default value is 0 and no message is sent. clientAliveInterval 60 indicates that the request is sent once every minute, and then the client responds, so that the persistent connection is maintained. clientAliveCountMax. Use the default value of 3. clientAliveCountMax indicates that after the server sends a request, the client will be automatically disconnected If no response is received by the client. normally, the client does not respond. Remember to restart the ssh service, otherwise it will not take effect. The restart code is as follows:

[root@chen /]# systemctl restart sshd.service[root@chen /]# 

Then OK. In addition, the command that quietly tells you whether the ssh service has been started is:

[Root @ chen/] # systemctl status sshd. service? Sshd. service-OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd. service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-09-21 16:57:34 CST; 2 min 35 s ago Docs: man: sshd (8) man: sshd_config (5) main PID: 9640 (sshd) CGroup:/system. slice/sshd. service Release 9640/usr/sbin/sshd-D

If running is enabled, enter

systemctl start sshd.service

The startup is complete. If you set auto start, enter:

systemctl enable sshd.service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.