How to add multiple authorized keys in Ubuntu

To add multiple authorized keys for a user in Ubuntu, you can follow these steps:

  1. Log in to the Ubuntu machine as the user for whom you want to add the authorized keys.

  2. Create a directory named .ssh in the user's home directory, if it doesn't already exist. You can do this with the following command:

    mkdir -p ~/.ssh
  3. Change the permissions on the .ssh directory to 700 (read, write, and execute for the owner only):

    chmod 700 ~/.ssh
  4. Create a file named authorized_keys in the .ssh directory. You can do this with the following command:

    touch ~/.ssh/authorized_keys
  5. Open the authorized_keys file in a text editor.

  6. Copy and paste each public key that you want to add into a new line in the authorized_keys file.

  7. Save and close the authorized_keys file.

  8. Change the permissions on the authorized_keys file to 600 (read and write for the owner only):

    chmod 600 ~/.ssh/authorized_keys

After completing these steps, the user will be able to log in via SSH using any of the public keys that you added to the authorized_keys file.


TAGS

ubuntu