SSH login to the virtual machine fails. How do I resolve this?

SSH login failures can manifest in several ways. Identify the applicable symptom and cause, then follow the corresponding solution to resolve the issue.

Symptom

SSH login failures may present as the following three symptoms:

  • Symptom 1: The root user cannot log in to the virtual machine via SSH.
  • Symptom 2: SSH connection to the business virtual machine fails with the error: Permission denied, please try again. error: Could not get shadow information for root.
  • Symptom 3: SSH login to the virtual machine times out.

Cause 1

Symptom 1 may occur because the SSH service configuration file does not allow root login.

Solution

  • Run the following commands in the virtual machine to edit the configuration file and allow root user login:

    [root@localhost ~]#  vim /etc/ssh/sshd_config
    PermitRootLogin yes

Cause 2

Symptom 2 may occur because the SELinux configuration file is blocking the SSH service.

Solution

  1. Run the following command in the virtual machine to update the SELinux configuration file to allow the SSH service:

    [root@localhost ~]#  semanage port -a -t ssh_port_t -p tcp 22
  2. Run the following commands to stop and disable SELinux:

    [root@localhost ~]#  setenforce 0
    [root@localhost ~]#  sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

Cause 3

Symptom 3 may occur because GSSAPI-based user authentication is enabled on the virtual machine. When enabled, the system performs a reverse DNS lookup on the server IP address during login. If the server IP address does not have a PTR record configured, login may be slow or time out.

Solution

  • Run the following command in the virtual machine to edit the sshd service configuration file:

    [root@localhost ~]# vim /etc/ssh/sshd_config
    UseDNS no
    GSSAPIAuthentication yes

On this page