Linux SysOps SSH login troubleshooting and solutions

WBOY
Release: 2023-09-26 17:46:50
Original
1703 people have browsed it

Linux SysOps SSH登录问题排查与解决方法

Linux SysOps SSH login problem troubleshooting and solutions

Introduction:
In Linux system operation and maintenance, SSH is a remote login tool we often use, but Sometimes we encounter SSH login problems, which brings trouble to our work. This article will introduce several common SSH login problems and provide corresponding solutions, as well as specific code examples.

1. Remote connection refused problem
Problem description:
When we try to remotely connect to the Linux server through SSH, we may encounter the error message "Connection refused" or "Connection timed out" .

Solution:

  1. To ensure that the SSH service has been started, you can use the following command to check:

    systemctl status sshd
    Copy after login

    If the service is not started, you can use the following command Start the service:

    systemctl start sshd
    Copy after login
  2. Check the server-side firewall settings to prevent the port from being blocked. You can use the following command to view the current firewall rules:

    iptables -L
    Copy after login
    Copy after login

    If you find that the SSH port number is banned, you can use the following command to open the corresponding port:

    iptables -I INPUT -p tcp --dport 22 -j ACCEPT
    iptables-save
    Copy after login

2. Password Key verification failure problem
Problem description:
When we use the key to log in to SSH, we sometimes encounter the error message "Permission denied (publickey)".

Solution:

  1. Check the permission settings of the key file to ensure that only the owner can read it and others do not have permission. You can use the following command to modify the key file permissions:

    chmod 600 ~/.ssh/id_rsa
    Copy after login
  2. Confirm that the corresponding public key has been added to the server. You can use the following command to view the list of public keys that have been added on the server:

    cat ~/.ssh/authorized_keys
    Copy after login
  3. If the public key is not configured correctly on the server, you can use the following command to copy the public key of the local computer to the server. :

    ssh-copy-id user@server-ip
    Copy after login

3. Connection timeout problem
Problem description:
When we try to connect to the Linux server, we may encounter the problem of no response for more than the specified time.

Solution:

  1. Check whether the network connection is normal. You can use the following command to check the network connection status:

    ping server-ip
    Copy after login
  2. Modify the connection timeout of the SSH client. Corresponding settings can be made in the configuration file of the SSH client. Open the configuration file "/etc/ssh/ssh_config", find the two parameters "ServerAliveInterval" and "ServerAliveCountMax", and set them to appropriate values ​​respectively, for example:

    ServerAliveInterval 60
    ServerAliveCountMax 3
    Copy after login

4. Login failed Number of times limit problem
Problem description:
When we fail to log in multiple times, the system may restrict login.

Solution:

  1. Check whether there are iptables rules that restrict login. You can use the following command to view iptables rules:

    iptables -L
    Copy after login
    Copy after login
  2. If there are restrictive rules, you can use the following command to delete the corresponding rules:

    iptables -D INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
    iptables -D INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 -j DROP
    iptables-save
    Copy after login

Conclusion:
Through this article, we learned some common SSH login problems and solutions, and provided specific code examples. It is hoped that these methods can help readers troubleshoot and solve SSH login problems more effectively and improve the efficiency of operation and maintenance work. At the same time, we also remind everyone to be careful when making configuration changes in the operating system to avoid irreparable damage to the system.

The above is the detailed content of Linux SysOps SSH login troubleshooting and solutions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template