Managing user’s access to files and folders are made easy by adding the users into required groups and giving required permissions to the group. By adding the users to that group, user will get all the access given to the group. Thereby giving separate access to the users are made simple. In this following post, you will learn how to create a new group and provide sudo access to group in linux.
Prerequisites:
1. Sudo access user account.
Things to Mind before adding a user into sudo group :
- Ensure you are in the correct host machine using hostname command.
- Confirm the group which is going to create is not already available.
Here are the steps on how to create a new group in linux.
Step 1 : Ensure there is no group present with the name you are going to create using below command.
sudo grep –i <groupname> /etc/group
Step 2 : If not available, execute below command to create a new group.
sudo groupadd <groupname>
Step 3 : Verify the newly created group using the command showed in step 1.
Step 4 : Edit the /etc/sudoers file and add the new group name after the line “Allows people in group wheel to run all commands” using below command and save the file using (Esc) followed by :wq!
sudo visudo
%developers ALL=(ALL) ALL
Step 4 : For adding a user into newly created group with user’s primary group, execute below command.
sudo usermod –g <groupname> <username>
-g – to force use new group as a primary group of the user.
Or
If you want to add a user into secondary group without changing the existing primary group or not removing the existing groups of the user. Use below command. sudo usermod -aG <groupname> <username>
-a – To append with the existing groups.
Step 5 : Verify the user’s group using below command.
id <username>
To learn how to create a user accounts in linux, Click here.
How do you feel about this post? Drop your comments below..