To add your public SSH key to a remote Ubuntu or Debian server, follow these steps:
-
Copy your public SSH key to your clipboard.
-
Connect to the remote Ubuntu server using SSH. Note that whatever user you connect as is also going to be the same as the account which we are adding the SSH keys.
-
Once you are connected to the server, create a
.ssh
directory in your home directory if it doesn't already exist:mkdir ~/.ssh
-
Open the
authorized_keys
file in a text editor, such asnano
:nano ~/.ssh/authorized_keys
-
Paste your public SSH key into the
authorized_keys
file. You can do this by right-clicking in the terminal window and selecting "Paste" from the context menu, or by using thepaste
command innano
:Ctrl+Shift+V
-
Save the
authorized_keys
file and exit the text editor. -
Set the correct permissions on the
.ssh
directory andauthorized_keys
file:chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
That's it! You should now be able to use your SSH key to log in to the remote server.
Here are a few additional tips:
-
If you want to add the public key to a different user on the remote server, you will need to repeat these steps as that user. You can switch to a different user by running the
su
command:su other_user
Replace "other_user" with the username of the user you want to switch to. You will need to enter the password for that user when prompted.