How to connect via SSH as root with a password or key
Written by
Updated at November 27, 2023
Scenario description
You need to connect via SSH from root with a password or key.
Solution
Connecting with a key
Connecting with a password.
To connect via SSH with a key, make sure that the /root/.ssh/authorized_keys
file contains only the key. Everything preceding the key needs to be deleted.
To connect via SSH with a password:
-
Create a password for root using the
sudo passwd root
command. -
The
/root/.ssh/authorized_keys
file must be empty or contain only the key. If the key does not match, the file will request a password. -
The
/etc/ssh/sshd_config.d/50-cloud-init.conf
file must contain:
PasswordAuthentication yes
PermitRootLogin yes