By default, Ubuntu and Debian forbid logging in as root via SSH with a password. For some purposes – backup scripts, Ansible, or tools such as Tabby or WinSCP on the home network – direct root access is practical nonetheless. Here is how to enable it while staying as secure as possible.
The PermitRootLogin options
| Value | Meaning |
|---|---|
prohibit-password | Default: root with an SSH key only, not with a password |
yes | root with key and password |
no | root login forbidden entirely |
forced-commands-only | Only with a key that is restricted to a specific command |
Important: with the default value prohibit-password, root login with a key is already allowed. In most cases nothing needs to be changed in the configuration at all – only the key is missing.
Recommended: root login with a key
On your own machine, generate a key (if none exists yet) and display the public part:
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub
On the server, as a normal user with sudo rights, store the key for root:
sudo mkdir -p /root/.ssh
sudo nano /root/.ssh/authorized_keys # paste the public key
sudo chmod 700 /root/.ssh
sudo chmod 600 /root/.ssh/authorized_keys
After that, ssh root@server works without a password.
Allowing root login with a password
If it really has to be the password, root needs one first:
sudo passwd root
The setting is best placed in a file of its own instead of editing sshd_config – that way it survives package updates:
echo 'PermitRootLogin yes' | sudo tee /etc/ssh/sshd_config.d/10-root-login.conf
Pitfall: sshd uses the first value it finds. The files in /etc/ssh/sshd_config.d/ are read in alphabetical order. If another file there (e.g. 50-cloud-init.conf on cloud servers) already sets a value, the file with the lower name wins – hence the 10- in the file name.
Test and apply
sudo sshd -t # check the syntax
sudo sshd -T | grep -i permitrootlogin # the value actually in effect
sudo systemctl restart ssh
On Ubuntu and Debian the service is called ssh, on Fedora and RHEL sshd. Tip: keep the existing SSH session open and test the login in a second window. If something goes wrong, you can still fix it that way.
Security notes
- Never allow root login with a password on servers that are reachable from the internet – automated password attacks run against them around the clock.
- If you need it anyway, block failed attempts with fail2ban and restrict access to known IP addresses with a firewall.
- On a home network, password login can be limited to specific networks:
PermitRootLogin prohibit-password
Match Address 192.168.178.0/24
PermitRootLogin yes
Originally published in 2016 for Ubuntu 16.04, completely revised in November 2026.