Do we need to reboot after adding a user to sudoers?
Solution 1
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
Solution 2
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.
Solution 3
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.
Solution 4
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
'"
Solution 5
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).
Related videos on Youtube
![Ashish Karpe](https://i.stack.imgur.com/a3oSD.png?s=256&g=1)
Ashish Karpe
Aws DevOps Engineer at ScreenCloud Bangkok, Thailand Managing Deployments on Kubernetes (Docker) Cluster using DevOps tools for Aws cloud infrastructure. Migration: Migrating K8s cluster on Aws ec2 instances to AWS EKS using terraform Setting ISTIO for observability, Converting Deployments to Helm Charts Creating Jenkins CI/CD pipeline for iOS and Android build using Unity and Xcode to push Application to App Center. Tools and Technology stack working: Git, Jenkins for CI / CD pipeline, Prometheus, Grapahna and Aws Cloudwatch - SNS service for monitoring and alerting to slack channel, setting up EFK using Terraform and Alerting application error logs to slack channel, Cassandra for no NoSql, PostgreSQL in RDS, Kafka for Distributed messaging, NGINX web server, OpenVPN, Memcached and Redis for caching, Hadoop, Spark for managing Big Data Analytics, Os primarily Linux and few windows boxes, Spring Boot Java application, Jira and Confluence.
Updated on September 18, 2022Comments
-
Ashish Karpe almost 2 years
Do we need to reboot after adding a user to
/etc/sudoers
?-
kos almost 9 yearsHave you tried running
sudo
before rebooting? -
Ashish Karpe over 7 years@kos have you down voted according to your comment ? if yes then you got my question wrongly.
-
-
Nathan B over 6 yearsI had to reboot as well.
-
Nick Rice about 6 yearsOn 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 about 6 yearsInstead of rebooting you can do
sudo service sudo restart
-
Necktwi almost 6 years@NickRice any idea on what to do in Arch Linux?
-
user2066480 almost 5 yearsWhat if $
sudo service sudo restart
outputs 'Failed to restart sudo.service: Unit sudo.service is masked.' -
xeruf over 3 years
Failed to restart sudo.service: Unit sudo.service is masked.
? -
Admin about 2 yearssudo 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/…