15%

Alexhost grants you wishes

Take the survey and win prizes

ALEX26
Get Started
25.11.2024

How to Enable root login Over ssh in Ubuntu

How to Enable Root Login via SSH on Ubuntu

By default, Ubuntu disables root login over SSH for security reasons. This restriction helps protect servers from unauthorized access, as the root account has full control over the system. However, in certain situations—such as troubleshooting or performing advanced administrative tasks—it may be necessary to enable root login via SSH. This guide walks you through the process of enabling root SSH login on Ubuntu and highlights important security considerations.

Important Security Considerations

Before enabling root login over SSH, be aware that this can significantly increase security risks. Consider the following precautions:

  • Use a strong password: Ensure the root password is complex and difficult to guess.
  • Enable a firewall: Use
    ufw
    or another firewall to allow SSH access only from trusted IP addresses.
  • Use SSH keys: It is strongly recommended to use SSH key-based authentication instead of relying solely on passwords.
  • Disable root login after use: Once administrative tasks are complete, disable root SSH login to reduce potential attack vectors.

Prerequisites

  • A user account with
    sudo
    privileges.
  • SSH access to your Ubuntu server.

Step 1: Set or Enable the Root Password

If the root account does not have a password set, you must define one. Ubuntu disables direct root login by default by not setting a root password. To set or change the root password, run the following command:

sudo passwd root

You will be prompted to enter and confirm a new root password. Choose a secure password. Once completed, the root account will be enabled.

Step 2: Edit the SSH Configuration File

To allow root login over SSH, you need to modify the SSH daemon configuration file.

  1. Open the SSH configuration file using your preferred text editor, for example:

sudo nano /etc/ssh/sshd_config

  1. Locate the following line:

PermitRootLogin prohibit-password

This setting allows root login only via SSH keys and disables password-based authentication.

  1. Change the line to:

PermitRootLogin yes

This change allows the root user to log in using a password.

Save the file and exit the editor. In

nano
, press
CTRL + O
, then
Enter
, and exit with
CTRL + X
.

Step 3: Restart the SSH Service

To apply the changes, restart the SSH service:

sudo systemctl restart ssh

Alternatively, you can use:

sudo service ssh restart

This will apply the new configuration and enable root login via SSH.

Step 4: Test Root SSH Login

After enabling root login, test the configuration:

  1. Open a terminal or SSH client.
  2. Connect to your server as root:

ssh root@your_server_ip

  1. Enter the root password you configured earlier.

If everything is configured correctly, you should now be logged in as the root user.

Step 5: Revert Changes After Use (Recommended)

For security reasons, it is best to disable root SSH login once your tasks are complete. To do this:

  1. Open the SSH configuration file again:

sudo nano /etc/ssh/sshd_config

  1. Change the
    PermitRootLogin
    setting back to:

PermitRootLogin prohibit-password

  1. Restart the SSH service:

sudo systemctl restart ssh

This will disable direct root SSH access again, ensuring that administrative access is performed through user accounts with

sudo
privileges.

15%

Alexhost grants you wishes

Take the survey and win prizes

ALEX26
Get Started