It’s completely incomprehensible why Linux Ubuntu developers made it very difficult to set up accounts. Because of this, many users cannot add the user to the Linux group. Yes, now you can’t manage groups, and such innovations are not always beneficial. From memory, everyone is trying to add the user to the Linux group by going to the “Accounts” settings, but the usual functionality is missing there. It is not clear why this innovation was made, but there are most likely reasons. Fortunately, this can be done differently.
Ways to add a user to a Linux group
Let's start with the simplest. To add to groups, use the simple useradd or usermod command. Using the first command, you can add a new user or simply update information about an already created one. The second command modifies an existing user. All information about groups and members can be found in the following files: / etc / passwd, / etc / shadow or / etc / group.
When using commands, you must understand which group and user you are adding to. By default, the group will match the username. That is, for user user1, his main group will also be user1. Initially, he needs to ask his main group. And only then can the user be added to the secondary groups.
Useradd example
As we said above, this team adds a new member to an existing group. If the secondary group does not exist, we can create it.
To add a Linux user to a group with sudo, use the command:
sudo useradd -G {group1} username
Here, "-G" allows you to assign a group to the user. It’s not necessary to use just one group name. They can be listed with commas. A simple example: we need to add the user alexey to the following groups: www, admins, test. The syntax will be as follows:
# useradd -G admins, test, www, alexey
To add a user to the root group on Linux, you just need to assign the name of this group, that is, root, with a comma. As a result, alexey will be added to the comma-separated groups.
If the desired group does not exist, then it must be created. It is created by the command: sudo groupadd group_name
In place of "group_name" can be any group name.
If you don’t know which group (or groups) the user is in, then this can be easily checked with the command: # sudo id user_name.
Usermod example
Suppose we need to add user alexey to the test group. We use the command:
# usermod -a -G test alexey
But to change the primary group to the same user, the command will be slightly different:
# usermod -g test alexey
All these basic steps will help to add a user to a group on Linux. In general, this system is extremely flexible, and almost any tasks can be solved using the terminal when the necessary functionality is not provided in the interface. With the update, some functions will disappear from the panel, some will appear, but the list of commands and their purpose do not change and are unlikely to ever change. It will be just stupid. Therefore, always try to control the Linux operating system, Ubuntu in particular, using simple commands. This will save a lot of time.
That's all. Keep this information, because it is impossible to memorize such commands quickly. So you will not waste time searching for the necessary information.