How to Enable SSH Root Login on Ubuntu

How to Enable SSH Root Login on Ubuntu

Secure Shell (SSH) is a cryptographic network protocol used for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers.

By default, many Ubuntu installations disable the SSH root login to enhance security. However, there are scenarios where enabling SSH root login can be beneficial, such as for administrative tasks or automation.

In this guide, we’ll walk you through the steps to enable SSH root login on Ubuntu. Before making any changes, it’s essential to understand the security implications and ensure that you have strong, unique passwords or SSH key authentication in place.

Let’s get started.

Step 1: Login as a sudo user

To enable SSH root login, you need to have sudo access. So, first, log in as a user with sudo access to your Ubuntu server.

ssh [sudo_user]@[server_ip_address]

Step 2: Backup SSH Configuration File

Before making any changes, it’s always a good practice to back up the configuration files. This ensures that you can revert to the original settings if something goes wrong.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

Step 3: Modify the SSH Configuration

Open the SSH daemon configuration file using a text editor like nano:

sudo nano /etc/ssh/sshd_config

Search for the line that reads:

PermitRootLogin prohibit-password

Change it to:

PermitRootLogin yes

This modification allows the root user to log in via SSH.

See also  How to Uninstall Webmin & Usermin on Ubuntu

Step 4: Restart the SSH Service

For the changes to take effect, you need to restart the SSH service:

sudo systemctl restart sshd

Step 5: Test the Root Login

From another machine, try logging in as the root user:

ssh root@your_server_ip

If everything is set up correctly, you should be able to log in without any issues.

Step 6: Strengthen Security (Optional but Recommended)

If you decide to enable SSH root login, it’s crucial to enhance security:

  • Use SSH Keys: Instead of relying on passwords, set up SSH key authentication.
  • Change Default SSH Port: Modify the default port (22) to a higher number to reduce brute-force attacks.
  • Install Fail2Ban: This tool can block IP addresses that show malicious signs.

Commands Mentioned

  • sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup – Backs up the SSH configuration file.
  • sudo nano /etc/ssh/sshd_config – Opens the SSH configuration file in nano editor.
  • sudo systemctl restart sshd – Restarts the SSH service.
  • ssh root@your_server_ip – Logs in as the root user via SSH.
See also  How to Uninstall Cassandra on Ubuntu


  1. Why is SSH root login disabled by default on Ubuntu?

    SSH root login is disabled by default on Ubuntu to enhance security. Logging in as the root user can pose significant risks, as it grants full access to the system. By disabling root login, potential attackers are deterred from gaining complete control over the server.

  2. Is it safe to enable SSH root login?

    Enabling SSH root login can be risky if not secured properly. If you choose to enable it, ensure you use strong authentication methods, such as SSH keys, change the default SSH port, and employ tools like Fail2Ban to monitor and block suspicious activities.

  3. How can I further secure my SSH connection?

    To further secure your SSH connection, use SSH key authentication, change the default SSH port, limit the number of login attempts, employ IP whitelisting, and utilize tools like Fail2Ban to monitor and block malicious attempts.

  4. What is the role of the SSH configuration file?

    The SSH configuration file, located at /etc/ssh/sshd_config, contains settings that determine how the SSH daemon behaves. It allows administrators to define authentication methods, specify allowed users, set the default port, and more.

  5. Why is it essential to back up the SSH configuration file?

    Backing up the SSH configuration file ensures that you have a fallback option. If any changes lead to issues or if the SSH service fails to start, you can quickly revert to the original settings using the backup.

See also  How to Install Bind DNS Server on CentOS and RHEL


Enabling SSH root login on Ubuntu can be a straightforward process, but it’s essential to approach it with caution. While it offers convenience for administrative tasks, it can also expose your server to potential threats if not secured correctly.

Always prioritize security by using strong authentication methods and monitoring tools. And remember, whether you’re setting up a new server or optimizing an existing one, always consider the best dedicated servers and best VPS hosting options to ensure optimal performance and security.


Leave a Reply

Your email address will not be published. Required fields are marked *