To add your public SSH key to a remote Ubuntu or Debian server, follow these steps:

  1. Copy your public SSH key to your clipboard.

  2. 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.

  3. Once you are connected to the server, create a .ssh directory in your home directory if it doesn't already exist:

    mkdir ~/.ssh

  4. Open the authorized_keys file in a text editor, such as nano:

    nano ~/.ssh/authorized_keys

  5. 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 the paste command in nano:

    Ctrl+Shift+V

  6. Save the authorized_keys file and exit the text editor.
  7. Set the correct permissions on the .ssh directory and authorized_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.
Was this answer helpful? 0 Users Found This Useful (0 Votes)