In Ubuntu, root login via SSH is disabled by default for security reasons. Enabling it can be useful for certain administrative tasks, but it also makes your system more vulnerable to unauthorized access. Follow these steps carefully to enable and, if desired, disable root login after completing your tasks.
Step 1: Enable the Root Account
Ubuntu locks the root account by default, which means no password is set. Before enabling SSH root login, you need to set a password for the root user.
Log in to the server: Access your Ubuntu server as a user with sudo privileges.
Set the root password: Run the following command to set a password for the root user:
Confirm the password: Enter and confirm the new password when prompted. This unlocks the root account and sets the specified password.
Step 2: Modify SSH Configuration to Permit Root Login
Now, adjust the SSH configuration to allow root login.
Open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
|
Locate the PermitRootLogin setting:
Change the setting:
If the line is commented out (e.g., # PermitRootLogin no), remove the # symbol to uncomment it.
Save and exit: In nano, press CTRL + X, then Y to confirm, and hit Enter to save.
Step 3: Restart SSH Service
After modifying the SSH configuration, restart the SSH service to apply the changes.
sudo systemctl restart ssh
|
Step 4: Test Root SSH Login
Now that root login is enabled, test it to ensure it's working as expected.
Log in as root: On your local machine, run the following command, replacing with your server's IP address:
Enter the root password: When prompted, enter the root password you set in Step1.
If configured correctly, you should now be able to log in as root.
Important: Re-Disable Root Login for Security
Once you've completed the necessary tasks, it's highly recommended to disable root login to reduce security risks.
Reopen the SSH configuration file:
sudo nano /etc/ssh/sshd_config
|
Set PermitRootLogin to No:
Restart the SSH service:
sudo systemctl restart ssh
|
By re-disabling root login, you make it harder for unauthorized users to access your system.