ComputersOS

How to add a user to the Linux group using the command line?

It is completely unclear why the developers of Linux Ubuntu greatly complicated the configuration of accounts. Because of this, many users can not add a user to the Linux group. Yes, now you can not manage groups, and such innovations are not always beneficial. From memory, everyone tries to add a user to the Linux group by going to the "Accounts" settings, but there is no usual functional there. It is unclear why this innovation was made, but the reasons are likely to exist. It is possible to do it differently.

Ways to add a user to a Linux group

Let's start with the simplest. To add to groups, use the simple command useradd or usermod. With the help of the first command, you can add a new user or simply update the information about an already created one. The second command modifies the 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 which user you are adding. By default, the group will match the user name. That is, for user1, its main group will also be user1. Initially, he needs to specify his main group. And only then can the user be added to secondary groups.

Example of using the useradd command

As we said earlier, this command adds a new member to the existing group. If there is no secondary group, 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 the user to assign a group. It is not necessary to use only one group name. You can list them through commas. A simple example: we need to add alexey to the following groups: www, admins, test. The syntax is:

# Useradd -G admins, test, www, alexey

In Linux, to add a user to the root group, you just need to specify the name of this group, that is, root, through the comma. As a result, alexey will be added to the comma-separated groups.

If the desired group does not exist, then it needs to be created. It is created by the command: sudo groupadd group_name

In place of "group_name" can be any name of the group.

If you do not know which group (s) the user is in, it's easy to check: # sudo id user_name.

Example of using the usermod command

Let's say we need to add the alexey user to the test group. 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 elementary actions will help add a user to the group on Linux OS. In general, this system is extremely flexible, and almost any task can be solved with the help of the terminal, when the necessary functionality in the interface is not provided. 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 silly. Therefore, always try to manage the Linux operating system, Ubuntu in particular, with simple commands. This will save a lot of time.

That's all. Save this information, because it is impossible to remember such commands quickly. So you will not waste time searching for the right information.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.