HOW TO ADD A PRIVATE SSH KEY TO USERS ON LINUX

When trying to use a private key as a new user, you must first create a .ssh directory for that new user, followed by creating an authorized_keys file inside of that .ssh directory for the user. Then, copy the key stored inside the authorized_keys file inside the .ssh directory under the /root directory.


Inside of the new user’s /home directory, create a directory called ‘.ssh’ by typing:

Mkdir .ssh


(The .ssh folder will be a hidden folder, and can only be seen by running ‘ls -a’)


Inside the .ssh directory run by typing:

touch authorized_keys


From your /root directory, run the following command:

cat /.ssh/authorized_keys >> /home/username/.ssh/auhtorized_keys


This will append what you have in /root’s authorized_keys file to the specified user’s authorized_keys file, allowing your new user access via private SSH.


READ: How to Create New Users and Grant Sudo Privileges to Users on Linux