Add users to wheel group linux

Configuring sudo and adding users to Wheel group

If a server needs to be administered by a number of people it is normally not a good idea for them all to use the root account. This is because it becomes difficult to determine exactly who did what, when and where if everyone logs in with the same credentials. The sudo utility was designed to overcome this difficulty.

With sudo (which stands for “superuser do”), you can delegate a limited set of administrative responsibilities to other users, who are strictly limited to the commands you allow them. sudo creates a thorough audit trail, so everything users do gets logged; if users somehow manage to do something they shouldn’t have, you’ll be able to detect it and apply the needed fixes. You can even configure sudo centrally, so its permissions apply to several hosts.

The privileged command you want to run must first begin with the word sudo followed by the command’s regular syntax. When running the command with the sudo prefix, you will be prompted for your regular password before it is executed. You may run other privileged commands using sudo within a five-minute period without being re-prompted for a password. All commands run as sudo are logged in the log file /var/log/messages.

The sudo configuration file is /etc/sudoers . We should never edit this file manually. Instead, use the visudo command: # visudo

This protects from conflicts (when two admins edit this file at the same time) and guarantees that the right syntax is used (the permission bits are correct). The program uses Vi text editor.

All Access to Specific Users
You can grant users bob and bunny full access to all privileged commands, with this sudoers entry.
user1, user2 ALL=(ALL) ALL
This is generally not a good idea because this allows user1 and user2 to use the su command to grant themselves permanent root privileges thereby bypassing the command logging features of sudo.

Access To Specific Users To Specific Files
This entry allows user1 and all the members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, plus the privilege of running the command /usr/apps/check.pl.
user1, %operator ALL= /sbin/, /usr/sbin, /usr/apps/check.pl

Access to Specific Files as Another User
user1 ALL=(accounts) /bin/kill, /usr/bin/kill, /usr/bin/pkill

Access Without Needing Passwords
This example allows all users in the group operator to execute all the commands in the /sbin directory without the need for entering a password.
%operator ALL= NOPASSWD: /sbin/

Adding users to the wheel group
The wheel group is a legacy from UNIX. When a server had to be maintained at a higher level than the day-to-day system administrator, root rights were often required. The ‘wheel’ group was used to create a pool of user accounts that were allowed to get that level of access to the server. If you weren’t in the ‘wheel’ group, you were denied access to root.

Читайте также:  Connect function in linux

Edit the configuration file (/etc/sudoers) with visudo and change these lines:
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

# Uncomment to allow people in group wheel to run all commands
%wheel ALL=(ALL) ALL

This will allow anyone in the wheel group to execute commands using sudo (rather than having to add each person one by one).

Now finally use the following command to add any user (e.g- user1) to Wheel group
# usermod -G10 user1

Источник

Learn Linux wheel group usage [With Examples]

Operating systems have a user with full privileges. However, since this user cannot be shared with the people logged into that system, they temporarily share some of their privileges with other users.
On Linux systems, the root user is the most authorized user. There is the sudo/wheel group for other users to use some of the privileges.
This group, which is called sudo in Debian based systems, is called wheel in Redhat and Arch base systems.

Users are taken to this group and authorized.

Confirm that you have the root user password before intervening in the wheel group. You may lose your authorization after an incorrect operation. We recommend that you perform these authorization processes with the root user.

Configuring Wheel Group in sudoers File

In the sudoers file, the wheel group is disabled in many Linux distributions. Even if the user is in this group, the following warning appears when he wants to perform an authorized transaction:

foc@fedora:~$ sudo cat /etc/sudoers | grep wheel [sudo] password for foc: foc is not in the sudoers file. This incident will be reported.
## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL ## Same thing without a password # %wheel ALL=(ALL) NOPASSWD: ALL

This issue is resolved by removing the # sign at the beginning of the %wheel lines. Users who are in the wheel group in the first wheel line can run all commands with their own passwords. In the second wheel line, users do not need to enter a password:

#%wheel ALL=(ALL) NOPASSWD: ALL

Opening this line is not recommended for security reasons.

It can open the sudoers file with an editor(vi,nano etc):

[root@fedora faruk]# nano /etc/sudoers

or you can use visudo command:

Open the first line in the sudoers file and try the same action again:

wheel group

foc@fedora:~$ sudo cat /etc/sudoers | grep wheel ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL # %wheel ALL=(ALL) NOPASSWD: ALL

Prevent wheel group users from changing root password

Wheel group users get root privileges temporarily. This authorization includes changing the root password. To prevent this, the sudoers file should be written like this:

%wheel ALL=(ALL) ALL, !/usr/bin/passwd root

After this operation, the user cannot change the root password even if user is in the wheel group:

faruk@fedora:~$ sudo passwd root Sorry, user faruk is not allowed to execute '/usr/bin/passwd root' as root on fedora.

Wheel Group Operations for Users

There are 2 methods to add/remove users to the wheel group. One is to use a command for this job, and the other is to manually edit the /etc/group file.

Читайте также:  Intel ax210 linux driver

Add/Remove Users to the wheel group by editing the group file

Edit the /etc/groups file with a text editor (vim, nano etc) in the terminal:

Learn Linux wheel group usage [With Examples]

Type users in the wheel group line, one after the other, with a comma(«,») between them.

Then, type sudo at the beginning of the commands you will type in the terminal to perform authorized action with the user. After the user enters his password, the action will take place:

[user1@fedora ]$ sudo cat /etc/sudoers [sudo] password for user1: ## Sudoers allows particular users to run various commands as ## the root user, without needing the root password. . 

To remove the user from the group, it is sufficient to delete the user from the wheel group line again. This step will prevent that user from taking authorized actions.

Add/Remove User from Wheel Group with Command

You have many alternatives for adding/removing users to the wheel group in Linux. When creating the user, you can create it by adding it to the wheel group with the adduser command:

[root@fedora faruk]# adduser user2 -G wheel

The added user is in the wheel group:

[root@fedora faruk]# cat /etc/group | grep wheel wheel:x:10:foc,faruk,user1,user2
[root@fedora faruk]# groups user2 user2 : user2 wheel

If the user is already added and you just want to put them in the wheel group, use the usermod command:

[root@fedora faruk]# usermod -aG wheel omer

The user is also included in the wheel group like this:

[root@fedora faruk]# cat /etc/group | grep wheel wheel:x:10:foc,faruk,user1,user2,omer

To remove the user from the wheel group, use the gpasswd command:

[root@fedora faruk]# gpasswd -d user1 wheel Removing user user1 from group wheel

This way user user1 is removed from wheel group:

[root@fedora faruk]# cat /etc/group | grep wheel wheel:x:10:foc,faruk,user2,omer

What you should do NEXT?

Summary

As we mentioned above, wheel group users are the most authorized users after root user. Care should be taken when adding/removing a user from this group.
Before adding/removing the wheel group, it should be ensured that the root password is known or you should switch to root user by logging in with an authorized user in a different terminal. Otherwise, you may lose all your privileges in that system.

In our article, we gave information about wheel, which is the super user authorization group in Linux.

References

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Как добавить пользователя в Sudoers в CentOS

sudo — это утилита командной строки, позволяющая доверенным пользователям запускать команды от имени другого пользователя, по умолчанию root.

Читайте также:  Linux узнать характеристики памяти

У вас есть два варианта предоставить пользователю доступ к sudo. Первый — добавить пользователя в файл sudoers . Этот файл содержит информацию, которая определяет, каким пользователям и группам предоставлены привилегии sudo, а также уровень этих привилегий.

Второй вариант — добавить пользователя в группу sudo, определенную в файле sudoers . По умолчанию в дистрибутивах на основе RedHat, таких как CentOS и Fedora, членам группы «wheel» предоставляются привилегии sudo.

Добавление пользователя в группу wheel

Самый простой способ предоставить привилегии sudo пользователю в CentOS — это добавить пользователя в группу «wheel». Члены этой группы могут запускать все команды через sudo и sudo запрос на аутентификацию с помощью своего пароля при использовании sudo .

Мы предполагаем, что пользователь уже существует. Если вы хотите создать нового пользователя, ознакомьтесь с этим руководством.

Чтобы добавить пользователя в группу , выполните приведенную ниже команду от имени пользователя root или другого пользователя sudo. Измените «имя пользователя» на имя пользователя, которому вы хотите предоставить разрешения.

usermod -aG wheel username

Предоставления доступа sudo с помощью этого метода достаточно для большинства случаев использования.

Чтобы проверить доступ sudo, выполните команду whoami :

Вам будет предложено ввести пароль. Если у пользователя есть доступ к sudo, команда выведет «root»:

Если вы получаете сообщение об ошибке «пользователя нет в файле sudoers», это означает, что у пользователя нет прав sudo.

Добавление пользователя в файл sudoers

Права sudo пользователей и групп настраиваются в /etc/sudoers . Добавление пользователя в этот файл позволяет предоставить настраиваемый доступ к командам и настроить настраиваемые политики безопасности для пользователя.

Вы можете настроить доступ пользователя sudo, изменив файл sudoers или создав новый файл конфигурации в каталоге /etc/sudoers.d . Файлы внутри этого каталога включены в файл sudoers.

Чтобы отредактировать файл /etc/sudoers , используйте команду visudo . Эта команда проверяет файл на наличие синтаксических ошибок при его сохранении. Если есть ошибки, файл не сохраняется. Если вы откроете файл в текстовом редакторе, синтаксическая ошибка может привести к потере доступа sudo.

Обычно visudo использует vim для открытия /etc/sudoers . Если у вас нет опыта работы с vim и вы хотите отредактировать файл с типом nano :

Допустим, вы хотите разрешить пользователю запускать команды sudo без запроса пароля. Откройте файл /etc/sudoers :

Прокрутите вниз до конца файла и добавьте следующую строку:

username ALL=(ALL) NOPASSWD:ALL 

Сохраните файл и выйдите из редактора . Не забудьте изменить «имя пользователя» на имя пользователя, которому вы хотите предоставить доступ.

Другой распространенный пример — разрешить пользователю запускать только определенные команды через sudo . Например, чтобы разрешить использование только команд du и ping :

username ALL=(ALL) NOPASSWD:/usr/bin/du,/usr/bin/ping 

Вместо редактирования файла sudoers вы можете добиться того же, создав новый файл с правилами авторизации в каталоге /etc/sudoers.d . Добавьте то же правило, что и в файл sudoers:

echo "username ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username

Такой подход делает управление привилегиями sudo более удобным в обслуживании. Имя файла не имеет значения. Обычно имя файла совпадает с именем пользователя.

Выводы

Предоставление доступа sudo пользователю — простая задача, все, что вам нужно сделать, это добавить пользователя в группу «wheel».

Если у вас есть вопросы, не стесняйтесь оставлять комментарии.

Источник

Оцените статью
Adblock
detector