Home  >  Article  >  Operation and Maintenance  >  How to solve SSH connection dropped and refused issues on Linux servers

How to solve SSH connection dropped and refused issues on Linux servers

WBOY
WBOYOriginal
2023-06-29 09:02:466369browse

How to solve the problem of SSH connection interruption and rejection on Linux server

In daily operation and maintenance work, using SSH (Secure Shell) for remote connection is a very common operation. Even though SSH is a secure and reliable protocol, you still sometimes encounter problems with connection interruptions and rejections. These problems can occur for a variety of reasons, and this article will cover some common solutions.

  1. Check the network connection
    First, confirm whether the network connection between the server and the local machine is normal. You can test the server's reachability through the ping command. If the server cannot be pinged, there is a problem with the network connection. You can check the connection between the server and the router, or contact the network administrator to solve the network problem.
  2. Check if the SSH service is running
    SSH connection problems may be caused by the SSH service not running properly. You can check the status of the SSH service with the following command:

    systemctl status sshd

    If the SSH service is not running, use the following command to start it:

    systemctl start sshd
  3. Check the SSH configuration file
    SSH connection issues It may also be related to incorrect settings in the configuration file. The SSH configuration file can be opened using a text editor for inspection. On most Linux distributions, the SSH configuration file is located at /etc/ssh/sshd_config. Make sure the following settings are correct:
  4. Port is set to the correct port number, which defaults to 22.
  5. PermitRootLogin is set to yes to allow root users to log in (if necessary).
  6. AllowUsers is set to the correct list of users allowed to log in.

If the configuration file is modified, please use the following command to restart the SSH service for the configuration to take effect:

systemctl restart sshd
  1. Firewall settings
    Firewalls may block SSH connect. You can check the status of the firewall with the following command:

    systemctl status firewalld

    If the firewall is running, you need to allow SSH traffic to pass. You can use the following command to open the port of the SSH service:

    firewall-cmd --permanent --add-service=ssh
    firewall-cmd --reload

    Please note that the specific firewall commands may vary depending on different Linux distributions.

  2. Check the SSH key
    SSH connection problems may also be related to the key. On the local machine, an appropriate private key is required for authentication. Make sure the private key is correct and matches the public key on the server. If the private key is damaged or lost, you can regenerate the SSH key pair and copy the public key to the server.
  3. Check login permissions
    SSH connection problems may also be related to login permissions. Make sure the user on the local machine has the correct login permissions. You can use the following command on the server to view the user's login permissions:

    cat /etc/passwd | grep username

    Make sure the user's login shell is set to an executable shell, such as /bin/bash.

  4. Check server load
    Excessive server load may cause SSH connections to be refused. You can check the server load through the following command:

    uptime

    If the load is too high, you can try to use some appropriate methods to reduce the load, such as stopping some processes that occupy more CPU resources.

Summary:
When troubleshooting SSH connection interruption and rejection issues on a Linux server, you first need to check the network connection and SSH service status. At the same time, factors such as SSH configuration files, firewall settings, SSH keys, login permissions, and server load should also be checked to ensure that these settings meet the requirements. Through these methods, we can solve SSH connection problems faster, thereby improving work efficiency.

The above is the detailed content of How to solve SSH connection dropped and refused issues on Linux servers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn