Tuesday, August 14, 2018

How to allow non-root users to control system.d services/utilities that needs root permissions.

How to allow non-root users to control system.d services/utilities that needs root permissions.

By default sudo is not installed on debian. So, install sudo
apt-get install sudo -y

Add current user to sodoers list
usermod -a -G sudo vq

Change editor for visudo (I love vim).
update-alternatives --config editor

Let's give user perrmision to reboot without password. First off all we should change configuration in /etc/sudoers file. In order to edit the fiole  use visudo:
vq ALL=NOPASSWD:/sbin/reboot

Usage (password is not required)
sudo reboot

Now let's allow user to access concrete system.d service without password. For example let's do it for firewalld service.

Create file
cd /etc/sudoers.d
touch vq
vim vq

Add the following configuration
%vq ALL= NOPASSWD: /bin/systemctl start firewalld
%vq ALL= NOPASSWD: /bin/systemctl stop firewalld
%vq ALL= NOPASSWD: /bin/systemctl status firewalld

Usage (password is not required)
sudo systemctl start firewalld
sudo systemctl stop firewalld
sudo systemctl status firewalld

Note that my user and group is called vq

.

No comments:

Post a Comment