Adding a Public SSH Key for Root Access

SSH keys provide a more secure method of logging into your server than using a password alone. By adding a public key to the root user, you can perform administrative tasks via terminal without needing a password.

Security Warning

Granting root access via SSH allows for full control over the server. Ensure you only add keys from trusted devices and never share your private key file.

Step-by-Step Configuration

  1. Locate and copy the contents of your public key file (usually ~/.ssh/id_rsa.pub or yourkeyname.pub).

    It should resemble the following format:

    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7sBaZnNypvT4tfPiEWEN2rrHKTV9pweD1BiFtOx1...I5f6GmQboRn1wpW61CjAYwNMTd user@workstation
  2. Access your server via terminal and open the authorized keys file for the root user:
    /root/.ssh/authorized_keys
  3. Paste the public key onto a new, single line at the end of the file.
  4. Save and close the file. The key will now have immediate access to the server as root.

Revoking Access

To remove access for a specific key, simply delete the line containing that public key from the /root/.ssh/authorized_keys file and save.