
On modern Ubuntu server installations, the root administrative account is locked by default with no usable password, and direct SSH password login as root is disabled. This security design prevents automated brute-force attacks against the root username across the public internet.
Instead, Ubuntu relies on the sudo (SuperUser DO) framework to grant administrative privileges to specific authorized users. This guide explains the best practices for logging in as root, elevating user privileges, setting up secure SSH key authentication, and safely enabling root login when required.
Method 1: Switch to root using sudo (Recommended)
The safest and standard way to execute administrative commands on Ubuntu is by logging in with your regular sudo user and elevating your shell.
Option A: Open an interactive root shell (Persistent)
To open a full root shell environment with root’s environment variables:
sudo -i
Or alternatively:
sudo su -
Enter your standard user password when prompted. Your command prompt will change from user@hostname:~$ to root@hostname:~#, indicating full administrative access.
Option B: Run a single command with root privileges
For one-off administrative tasks, prefix the command with sudo:
sudo apt update && sudo apt upgrade -y
Method 2: Set a root password (If account is locked)
By default, Ubuntu leaves the root account password unset. If your application or automation specifically requires a direct root password:
- Log in via SSH with your sudo user.
- Assign a new strong password to the root account:
sudo passwd root - Enter and confirm your new root password.
Method 3: Enable root SSH login via SSH Keys (Safest)
Allowing root login over SSH using password authentication is a severe security risk. However, allowing root login exclusively via cryptographic SSH keys is secure and standard practice for automated deployments.
Step 1: Copy your public key to root’s authorized_keys
# Switch to root
sudo -i
# Create the .ssh directory and set correct permissions
mkdir -p /root/.ssh
chmod 700 /root/.ssh
# Add your local public key to authorized_keys
nano /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
Step 2: Configure sshd to allow key-based root login
- Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config - Locate the
PermitRootLogindirective and set it toprohibit-password:PermitRootLogin prohibit-password(This allows SSH key logins for root while strictly blocking password brute-force attempts).
- Test the SSH configuration syntax:
sudo sshd -t - Restart the SSH service:
sudo systemctl restart ssh
How to enable password root login (If strictly necessary)
If you must enable password-based root login (e.g. for private lab environments or internal networks):
- Open
/etc/ssh/sshd_config:sudo nano /etc/ssh/sshd_config - Update the directive to:
PermitRootLogin yes PasswordAuthentication yes - Restart the SSH daemon:
sudo systemctl restart ssh
Emergency rescue via VNC Console
If an SSH configuration mistake or locked user account prevents you from connecting, log in to your Aminserve Client Area and open the out-of-band HTML5 VNC console as explained in our VNC rescue guide to reset credentials directly from the hypervisor.
For high-performance, developer-ready Linux servers with automated deployment, explore Aminserve Linux and Windows VPS hosting with 1Gbps ports and 24/7 dedicated support.








