- Удалить пользователя из группы Linux
- Удаление пользователя из группы Linux
- Выводы
- Remove Linux User From a Secondary Group ( Supplementary Groups )
- Step # 1: Find out user group identity
- Step # 2: Remove user from printer group
- How to Remove Linux User from a Group
- Create Linux User
- Adding a User to a Group
- Find out the Groups a User belongs
- Removing User from a Group Using usermod
- Removing User from a Group Using gpasswd
- Removing User from a Group (Manually)
- Conclusion
- [How To] Remove User from group in Linux
- How to Add or Remove a User from a Group in Linux
- Check a User Group in Linux
- Add a User to a Group in Linux
- Remove a User from a Group in Linux
- If You Appreciate What We Do Here On TecMint, You Should Consider:
Удалить пользователя из группы Linux
Группы пользователей в Linux используются для тонкой настройки доступа к файлам операционной системы. И поскольку в Linux все объекты ОС являются файлами, то с помощью групп можно настроить или ограничить доступ к любой возможности системы.
В одной из предыдущих статей мы говорили о том, как посмотреть список групп Linux, в которых состоит пользователь. В этой же заметке разберём, как удалить юзера из группы Linux, чтобы он больше не мог иметь доступа к файлам, которые находятся в этой группе.
Удаление пользователя из группы Linux
Очень много слов вступления, а дела не более чем на одну команду. Мы будем использовать gpasswd. Она имеет такой синтаксис:
gpasswd -d пользователь группа
Опция -d сообщает, что нужно выполнить удаление, далее мы указываем пользователя, с которым будем работать и в конце группу, из которой его надо удалить. Теперь откройте терминал с помощью сочетания клавиш Ctrl+Alt+T и наберите следующую команду, чтобы удалить пользователя testuser из группы wheel:
sudo gpasswd -d testuser wheel
С помощью команды usermod вы можете удалить текущего пользователя из всех дополнительных групп:
sudo usermod -G «» имя_пользователя
Только будьте осторожны с этой командой, применяя её к текущему пользователю, иначе вы удалите себя из группы sudo и больше не сможете выполнять административные действия. В Ubuntu, где нет прямого доступа к пользователю root это может создать серьёзные проблемы для новичков, смотрите статью сброс пароля в Ubuntu.
В некоторых дистрибутивах можно использовать ещё и команду deluser. Точно также указываем сначала имя пользователя, а затем группу, из которой собираемся его удалить:
sudo deluser testuser adm
Если вы случайно удалили пользователя из группы, в которой он должен быть, можно всё вернуть обратно. Смотрите статью «как добавить пользователя в группу Linux».
Выводы
В этой небольшой статье мы рассмотрели, как удалить пользователя из группы Linux. Как видите, это совсем не сложно, только надо соблюдать осторожность, чтобы не удалить ничего лишнего и не создать себе проблем. Если у вас остались вопросы, спрашивайте в комментариях! Почитать более подробно о группах можно в статье «группы пользователей Linux».
Источник
Remove Linux User From a Secondary Group ( Supplementary Groups )
Q. User tom is a member of a group called sales and printer. I’d like to remove tom from a group called printer without editing any user configuration text files stored at /etc/ directory?
A. /etc/groups file defines group membership for each user. usermod command has -G option to set a list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. If the user is currently a member of a group which is not listed, the user will be removed from the group.
Step # 1: Find out user group identity
Use id command:
# id -nG < user-name >
# id -nG tom
Output:
Step # 2: Remove user from printer group
Use the following syntax:
# usermod -G < groupname1,groupname2. > < username >
To keep membership for sales only group (remove user tom from printer group), enter:
# usermod -G sales tom
# id -nG tom
Output:
The following example remove user vivek from all groups except admin, audio, video and powerdev group:
# id -nG vivek
Output:
Modify group membership, enter:
# usermod -G admin, audio, video, powerdev vivek
# id -nG tom
Sample output:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
For more information, read usermod(8) command man page:
$ man usermod
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to Remove Linux User from a Group
A user can be a member of one primary and one or several secondary (supplementary) groups in Linux. The file ‘/etc/group’ defines group membership for each user in the Linux system.
In this tutorial, we will learn how to remove a user from a group in Linux. We will use two methods and also I will show how to manually remove the user from the group by deleting from ‘/etc/group’ file.
Create Linux User
For the purpose of this tutorial, we will create a user named ‘testuser’. When a new user is created, a new primary group with the same name for that user is created too.
We will create a new user by issuing the following command:
Now we can create a password for that user:
I used the same password as the username so I got a warning that the password shouldn’t contain the user name in some form.
Adding a User to a Group
First, we will create two new groups using groupadd command as follows:
Now we will add ‘testuser’ user to the above created two groups and also add to ‘root’ group using the following commands:
Ok, so now if we look at ‘/etc/group’ file and can see that ‘testuser’ is a member of all three groups.
Find out the Groups a User belongs
We can also use two alternative ways to check to which groups does a user belong as follows
As you can see the output is very similar and those commands accomplish the same thing.
Removing User from a Group Using usermod
We can remove a user from a group or several groups at once using usermod command. Using usermod you have to specify in which secondary groups you want to keep the user in. Let me explain with an example.
In order to remove user ‘testuser’ from ‘testgroup1’ and ‘testgroup2’ group run the below command ( ie leave testuser only in ‘root’ group and it’s primary ‘testuser’ group):
So in order to keep a user in more groups, you’ll need to mention group names separated by comma (,) like:
Removing User from a Group Using gpasswd
Another command that accomplishes similar results is gpasswd. We use this command to remove users from specified groups, unlike with usermod.
To remove a user from one specific group we can use gpasswd command:
Removing User from a Group (Manually)
We can also remove a user from a group by manually editing the file ‘/etc/group’. The effects of this method will apply to the user upon reboot.
You can use your favourite text editor to edit the ‘/etc/group’ file:
We will now manually edit the last two entries to delete testuser and remove it from testgroup1 and testgroup2 (edited file should look like this):
Changes will take place after reboot, and now the user has been removed from those two groups:
Conclusion
In this tutorial, we have learned how to remove a user from a group using usermod, gpasswd and also by manually deleting them from ‘/etc/group’ file.
These instructions can be used on any Linux system like Ubuntu, CentOS, Fedora and many others. If you have any questions, please let us know in the comments below.
Источник
[How To] Remove User from group in Linux
User groups are used to configure file system access of the operating system. Since in Linux all objects of the OS are files, then with the help of groups you can configure or restrict access to any features of the system.
In a previous article, we talked about how to see a list of Linux groups that the user is member of. Here we will discuss how to remove a user from the group, so it can no longer have access to the files with that group permissions.
We will use gpasswd command. It has the following syntax:
The -d option means remove.
For example lets remove testuser from the adm group:
With the usermod command you can remove the current user from all additional groups:
Just be careful with this command by applying it to the current user, otherwise you will remove yourself from the sudo group and will no longer be able to perform administrative actions. In Ubuntu, where there is no direct access to the root user, this can create serious problems for newbies.
In some distributions, you can also use the deluser command. In the same way, first specify the user name, and then the group name from which we are going to remove it:
If you accidentally delete a user from the group in which he should be, you can return everything back. See the article “How to add a user to a Linux group“.
Источник
How to Add or Remove a User from a Group in Linux
Linux is by default a multi-user system (meaning many users can connect to it simultaneously and work), thus user management is one of the fundamental tasks of a system administrator. User management includes everything from creating, updating, and deleting user accounts or user groups on a Linux system.
In this short quick article, you will learn how to add or remove a user from a group in a Linux system.
Check a User Group in Linux
To check a user group, just run the following groups command and provide the username (tecmint in this example) as an argument.
To check your own groups, just run the groups command without any argument.
Check a User Group in Linux
Add a User to a Group in Linux
Before trying to add a user to a group, ensure that the user exists on the system. To add a user to a certain group, use the usermod command with the -a flag which tells the usermod to add a user to the supplementary group(s), and the -G option specifies the actual groups in the following format.
In this example, tecmint is the username and postgres is the group name:
Add User to Group in Linux
Remove a User from a Group in Linux
To remove a user from a group, use the gpasswd command with the -d option as follows.
Remove User from Group in Linux
Additionally, on Ubuntu and it’s derivative, you can remove a user from a specific group using the deluser command as follows (where tecmint is the username and postgres is the group name).
For more information, see the man pages for each of the different commands we have used in this article.
You will also find the following user management guides very useful:
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник