Adding a Public SSH Key for Root Access

To grant root access to a server via SSH using a public key, follow these steps:

  1. Obtain the Public Key:

    • Copy the contents of the public SSH key file (e.g., yourkeyname.pub). It will look like this:
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7sBaZnNypvT4tfPiEWEN2rrHKTV9pweD1BiFtOx1...I5f6GmQboRn1wpW61CjAYwNMTd yourname@yourcomputer
    
  2. Access the Server:

    • SSH into the server as root.
  3. Edit the authorized_keys File:

    • Navigate to the .ssh directory for the root user: /root/.ssh/.
    • Open the authorized_keys file (create it if it doesn't exist).
  4. Paste the Key:

    • Paste the copied SSH public key into a new line within the authorized_keys file.
  5. Save and Exit:

    • Save the file and exit the editor.
  6. Key Removal (if needed):

    • To revoke access, simply delete the line containing the SSH key from the authorized_keys file and save it.

The SSH key will now have root access to the server.

Was this answer helpful? 0 Users Found This Useful (0 Votes)