Introduction :-
In the realm of #secure and efficient system administration, creating new user accounts on #Linux machines is a fundamental task. Adding an extra layer of #security, using #SSH keys for user authentication has become a best practice in the world of remote access. This guide delves into the process of creating a new user with an SSH key on a #Linux system, outlining steps that prioritize both #security and convenience.
Step-1 :- First, create a new user using below command.
sudo useradd -m -d /home/username -s /bin/bash username
Step-2 :- Then, copy the contents of the user’s public key into /home/username/.ssh/authorized_keys. This is a plain text file where you can paste one public key per line.
Step-3 :- After that, set up the correct permissions for both the .ssh directory and the authorized_keys file:
chown -R username:username /home/username/.ssh
# make sure only the new user has permissions
chmod 700 /home/username/.ssh
chmod 600 /home/username/.ssh/authorized_keys
Step-4 :- Last, if you want the new user to have sudo access, be sure to add them to the sudo group:
sudo usermod -a -G sudo username
If you don’t have a sudo group, you can manually edit the /etc/sudoers file.
Conclusion :-
As technology evolves, so does the importance of robust #security measures. Creating new user accounts while leveraging #SSH keys not only streamlines user authentication but also fortifies the defense mechanisms of a #Linux system. By following the steps outlined in this guide, #administrators can confidently establish new user accounts with heightened #security, enabling seamless remote access while safeguarding sensitive #data from unauthorized access. In a world where #security is paramount, embracing SSH key-based user creation is a significant stride towards a more secure and efficient Linux environment.