Do we need to reboot after adding a user to /etc/sudoers
?
5 Answers
No. It'll work with the next sudo
command.
But if it does not work, you can avoid rebooting by running
sudo service sudo restart
-
3On my 14.04 system it did not work with the next sudo command. I needed to do
sudo service sudo restart
(Rebooting would have worked too, I guess. Bit overkill though.) Jun 2, 2018 at 6:32 -
32
-
1sudo is masked, which means most
systemctl
commands don't work with it. There is no need to restart anything aftersudoedit
, though, so there shouldn't be a need to restart the sudo "service." Read more here: askubuntu.com/questions/816285/… May 30, 2022 at 6:53
I just did this and yes, I did in fact have to reboot. So, maybe the previous answer wasn't wrong, but it definitely isn't right 100% of the time. Writing this in case someone else is looking for the answer as I just was.
-
2
-
1
-
-
30What if $
sudo service sudo restart
outputs 'Failed to restart sudo.service: Unit sudo.service is masked.' Aug 2, 2019 at 12:31
In CentOS 7 you can also Logout from the system with "exit" and Login again and the Sudoers will be updated.
I've tested on minimal installation but I believe it works in other targets and possibly other distributions aswell.
In fact the only thing you need is to get a (new) login prompt, so using the following command works:
anyuser$ su -l <user>
user$ sudo <thenewlysudoedcommand>
... works...
But if you are logged in as GUI, then you need to logout & login again.
But, as with MOST linux tools you DON'T need to reboot the computer (that's a Windows thing).
After add user to sudo group,
#su - root -c "usermod -aG sudo username;"
execute following command:
newgrp sudo
And after that you can use sudo in your commands in current session without need to restart.
Also if you are in a shell script and you want to execute command just after add user to sudoers, run following command instead:
#su - root -c "usermod -aG sudo username;"
sg sudo -c 'sudo command1; sudo command2;'
And If you don't want to reapeat sudo word in each command do as follow:
sg sudo -c "sudo -- sh -c 'command1; command2;'"
OR
sg sudo -c "sudo -- sh -c '
command1
command2
'"
-
1Please be careful if you use
newgrp sudo
as this will modify that user's primary group. If you want an alternative that does not modify that user's primary group but instead updates that user's secondary group list to include the previously added group, please tryexec sg sudo newgrp
. More info here. HTH.– jaimetAug 12, 2023 at 13:34
sudo
before rebooting?