How to Add a User in Linux and Configure Permissions:
Managing users and their permissions is a fundamental task for Linux administrators. This ensures that users have the right access level to perform their tasks without compromising system security. In this article, we’ll guide you through the process of adding a user in Linux and configuring their permissions.
Add a New User in Linux
However, many administrators prefer the
adduser command (where available) because it’s more interactive and user-friendly:
ubuntu@Rushi-Infotech:/$ sudo adduser rushi
This command will prompt you to set a password(for the privacy issues Linux will hide the password) and may also ask for other details like the user’s full name, room number, etc.
Confirm with ” y ” to create user.
Once the user is created for confirmation use below command:
ubuntu@Rushi-Infotech:/$ sudo cat /etc/passwd
Here, we can see the user details.
Giving Permission for User to Connect Server with Password
- Will try to connect to server with the username and password
- We got an Error that “we cannot connect the server with the username and password other than public key”
- So we need to give permission to connect with password
Giving permission for the user to connect the server with username and password:
- Description: we need to edit the sshd_config file to give permission.
ubuntu@Rushi-Infotech:/$ sudo vi /etc/ssh/sshd_config
- In this file “password authentication” will have in the “no”. We need to convert it into “Yes”
- Now, to save and exit from the file we need to enter, “Esc , :wq” and press “Enter”.
Esc :wq and Enter
- To work the ssh services we need to restart the ssh services.
ubuntu@Rushi-Infotech:/$ sudo service ssh restart
- Now, you can connect with the username and password to the server.
Successfully you have connected to the Server.
Configuring User Permissions with sudo
For a user to execute commands with superuser privileges, they must be added to the
sudo group or specified in the sudoers file.
- Will try to create a file as a user:
ubuntu@Rushi-Infotech:~/$ sudo touch test1
We got an Error that user is not in the sudoers file.
- Edit the sudoers file:
First, open the sudoers file using the visudo command for safe editing:
ubuntu@Rushi-Infotech:/$ sudo visudo
Then, to give rushi full sudo privileges, add the following line:
rushi ALL=(ALL:ALL) ALL
- Now we will try to create a file as a user again.
Successfully we have created a file as a user.
How to Remove User
- We need to remove unnecessary users by following command:
ubuntu@Rushi-Infotech:/$ sudo deluser rushi
Managing users and their permissions is a routine but crucial task in Linux. By adding users and configuring their permissions correctly, you ensure that individuals can perform their tasks on the system while maintaining a high level of security. Always remember to periodically review user permissions and make adjustments as roles and responsibilities evolve.
To Know more about Linux visit official website.
Any queries pls contact us