Do we need to reboot after adding a user to /etc/sudoers?
- 16,703
- 2,557
- 3
- 20
- 24
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
- 18,154
- 1,399
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.
- 149
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
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
'"
- 151
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