An administrator can authorise an SSH public key for the root account when server policy permits direct root login. Keep the private key on the connecting device and retain an existing working session while testing.

Prepare the public key

Generate the key pair on your own device and copy its public key in OpenSSH format. It normally begins with an algorithm name such as ssh-ed25519 or ssh-rsa. Never paste a private key into authorized_keys.

Add the key

Using authorised root access, check the server’s configured AuthorizedKeysFile location. For the normal root location:

mkdir -p /root/.ssh
chmod 700 /root/.ssh

Open /root/.ssh/authorized_keys in an editor. Preserve existing entries and append the complete public key on one line. Save, then ensure the file belongs to root and is not accessible to other users:

chown root:root /root/.ssh /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys

On systems enforcing SELinux, confirm the appropriate file labels as well. A different authorised-key mechanism needs its own supported process.

Test access

Open a separate SSH connection using the private key and check that it reaches the intended server and account. Adding a key does not require restarting SSH.

The key cannot override a policy that disables direct root login. Use an authorised non-root account with sudo where that is the server’s policy, and keep the original session until the new access method is verified.