User and group management on Linux sounds pretty complex, but it’s actually quite easy. If you’ve had trouble understanding how to create new groups, delete existing groups, or modifying users on your system, don’t worry. As it turns out, even the most experienced of Linux users can easily forget the fundamentals. In this guide, we’ll go over all the ways you can manage groups and users on the Linux platform.
Create New Groups
Creating new groups isn’t something many users do, as most Linux distributions don’t need it. If you’re installing software or managing things in a way that requires a new group, the quickest way to accomplish this is with the command-line with the groupadd command.
To use groupadd, you’ll need root access, or at the very least, the ability to interact with the system via sudo privileges. Confirm that your user can do this, then open up a terminal and do the following to create a new group:
su - groupadd newgroup
or, alternatively, make a new group with sudo:
sudo groupadd newgroup
alternatively, create multiple groups at once:
su - groupadd newgroup, newgroup2, newgroup3
if (navigator.appVersion.indexOf(“Mac”)!=-1) document.write(”);
RECOMMENDED FOR YOU
sudo groupadd newgroup, newgroup2, newgroup3
Groupadd will create the new group on your Linux system. To confirm that the group is there, consider filtering through the list of groups on your PC.
cut -d: -f1 /etc/group | grep newgroup
By combining the above command with grep, it’s possible to filter out the new group you made. If the command returns nothing, try to create the user group again.
If you have no use for a certain group on your Linux PC, it’s a good idea to delete it. Removing a user group on Linux is as easy as creating a new one. First, log in as su, or confirm your user can execute sudo commands. Then, run the groupdel command to get rid of an existing group.
su - groupdel newgroup
sudo groupdel newgroup
Running groupdel should get rid of it. List all available groups on your PC to be sure.
cut -d: -f1 /etc/group | grep newgroup
If Grep doesn’t return anything, you’ll know for sure the group is gone.
Add/Remove Users To Groups
To add existing users to a newly created group, you’ll need to make use of the usermod command. Open up a terminal and use the cut command to view all groups. Go through the list and find the names of the groups you’d like to add your user to. Alternatively, use the name of the user group created earlier.
Note: like before, confirm you can log into Root with su, or that you’re able to use sudo before modifying critical user information.
su - usermod -a -G newgroup yourusername
sudo usermod -a -G newgroup yourusername
Confirm your user is added to the new group by running the following command:
Aside from managing groups on Linux, learning how to create and manage users is also key to maintaining a harmonious Linux system. Unlike group management, user tools are a lot less complicated. There’s not a whole lot of complexity to it. In this section of the guide we’ll go over how to create a new user on Linux with the command line and how to delete a user.
Create New User
Need to create a new user on your Linux system? Start out by opening up a terminal window. In the terminal, gain root access with su or sudo.
Now that you’ve got a root shell, it’ll be much easier to manipulate users without needing to add “sudo”, and a password over and over. To create a new user with a full home directory, run the command below.
Note: on some Linux PC’s you may need to replace “useradd” with “adduser”.
Alternatively, it’s possible to create a new user and assign groups to it at the same time:
useradd -G group1, group2, group3, group4, group5, group6 newuser
After creating the new user, set the password:
Deleting users on Linux is quite straightforward and easy. Getting rid of a user can easily be accomplished on Linux by making use of the userdel command.
Note: before continuing with deleting users, be sure to log out of everything. It’s a very bad idea to delete a user that is currently in use. Things can go wrong, and you’ll reget it.
Once you’ve made sure you’re not logged into the user you plan to delete, run:
userdel -r newuser
To delete the user but preserve the Home directory, run this command instead: