Do we need to reboot after adding a user to /etc/sudoers?
- 12,964
- 10
- 49
- 77
- 2,337
- 3
- 19
- 23
-
Have you tried running `sudo` before rebooting? – kos Aug 27 '15 at 10:05
-
@kos have you down voted according to your comment ? if yes then you got my question wrongly. – Ashish Karpe Jan 12 '17 at 11:46
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
- 17,416
- 26
- 64
- 103
- 1,343
- 11
- 16
-
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.) – Nick Rice Jun 02 '18 at 06:32
-
32
-
1sudo is masked, which means most `systemctl` commands don't work with it. There is no need to restart anything after `sudoedit`, though, so there shouldn't be a need to restart the sudo "service." Read more here: https://askubuntu.com/questions/816285/what-is-the-difference-between-systemctl-mask-and-systemctl-disable – gonzojive May 30 '22 at 06: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.
- 119
- 1
- 2
-
2
-
1
-
-
28What if $`sudo service sudo restart` outputs 'Failed to restart sudo.service: Unit sudo.service is masked.' – user2066480 Aug 02 '19 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.
- 181
- 1
- 6
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).
- 11
- 1
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
'"
- 111
- 2
-
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 try `exec sg sudo newgrp`. More info [here](https://stackoverflow.com/a/76889494/3499840). HTH. – jaimet Aug 12 '23 at 13:34