Adding a Public SSH Key for Root Access
To grant root access to a server via SSH using a public key, follow these steps:
-
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
- Copy the contents of the public SSH key file (e.g.,
-
Access the Server:
- SSH into the server as root.
-
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).
- Navigate to the
-
Paste the Key:
- Paste the copied SSH public key into a new line within the
authorized_keys
file.
- Paste the copied SSH public key into a new line within the
-
Save and Exit:
- Save the file and exit the editor.
-
Key Removal (if needed):
- To revoke access, simply delete the line containing the SSH key from the
authorized_keys
file and save it.
- To revoke access, simply delete the line containing the SSH key from the
The SSH key will now have root access to the server.