How to connect via SSH as root with a password or key
Written by
Updated at December 17, 2025
Case description
You need to connect via SSH as root with a password or key.
Solution
Connecting with a key
Connecting with a password
When connecting with a key, the /root/.ssh/authorized_keys file must contain only the key. Delete everything preceding the key, if any.
To connect via SSH with a password:
-
Create a password for root using the
sudo passwd rootcommand. -
The
/root/.ssh/authorized_keysfile must be empty or contain only the key. If the key does not match, the file will prompt you to enter a password. -
The
/etc/ssh/sshd_config.d/50-cloud-init.conffile must contain:PasswordAuthentication yes PermitRootLogin yes