How to Disable Remote Root Login on Ubuntu 24.04

Introduction

Remote root login allows you to connect to your server from another location, providing flexibility and convenience using superuser account details. However, this access presents security risks if not properly managed. Disabling remote root login can help protect your server from unauthorized access and potential attacks.

This article shows you how to disable remote root login on Ubuntu 24.04.

Prerequisites

Before you begin, ensure you've:

Edit the SSH Configuration File

In this section, you will edit the SSH configuration file to disable remote SSH login.

  1. Open the SSH configuration file using nano text editor.

    CONSOLE
    $ sudo nano /etc/ssh/sshd_config
    
  2. Find the line that starts with PermitRootLogin.

    INI
    PermitRootLogin yes
    
  3. Change the PermitRootLogin directive value to no to disable root login via SSH.

    INI
    PermitRootLogin no
    
  4. Restart the SSH service to apply the new configurations

    CONSOLE
    $ sudo systemctl restart ssh
    

Verify the Configuration

In this section, you will verify that remote root login is disabled.

  1. Use your SSH client, such as PuTTY in Windows or OpenSSH in Linux and macOS and attempt to log in to your server using the root user's credentials.

    CONSOLE
    $ ssh root@your_server_ip
    

    You should see a message indicating that the connection is refused or that authentication has failed, confirming you've disabled the remote root login.

Conclusion

You have disabled remote root login on your Ubuntu 24.04 server. This guide covered editing the SSH configuration file, restarting the SSH service, and verifying the configuration. Disabling remote root login enhances the security of your server by preventing unauthorized access. You can now manage your server through SSH using a non-root user with sudo privileges. Consider regularly reviewing and updating your security settings to maintain a secure server environment.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js