Creating a New User with SSH Access
Overview¶
This guide explains how to create a new user on a Linux system, configure SSH access, and grant sudo privileges if needed.
Steps¶
1. Create a New User¶
To create a new user, run the following command:
Important
Replace <username>
with the desired username
This command:
- -m
creates a home directory.
- -d /home/<username>
specifies the home directory.
- -s /bin/bash
sets Bash as the default shell.
2. Set the User’s Password¶
Assign a password to the new user:
Note
If you don’t want the user to have a password, set it to an empty string.
3. Configure SSH Access¶
Create the .ssh
Directory¶
Run:
Add the Public Key¶
To enable SSH key authentication, copy the user's public key into the authorized_keys
file:
This fetches the SSH key from the user's GitHub profile.
4. Set the Correct Permissions¶
Ensure the .ssh
directory is owned by <username>
:
Set appropriate permissions:
These permissions:
- Ensure only <username>
can access the .ssh
directory.
- Secure the authorized_keys
file.
5. Grant Sudo Privileges (Optional)¶
Change to root and then install sudo
To give <username>
sudo access, add them to the sudo group:
If the sudo
group does not exist, manually edit the /etc/sudoers
file:
Then add:
Warning
Be cautious when editing /etc/sudoers
. Incorrect changes can lock you out of sudo access.
Conclusion¶
You have now successfully created the user <username>
, configured SSH access, and optionally granted sudo privileges.