Is a reboot required to refresh permissions after adding a user to a new group?
On ubuntu server, I've noticed more than once now that after adding a user to a group that user doesn't have group permissions until I reboot the system. For example:
User 'hudson' needs permission to read directory 'root:shadow /etc/shadow' So I add hudson to the shadow group. hudson still cannot read. So, I 'sudo shutdown -h -r now' and when the system comes up again user hudson can read.
Is a reboot required or is there a better way to get permissions applied after adding the user to the group?
Solution 1:
I was looking for a solution, came across this post, and then later found one!
I'd thought I'd actually offer a solution so others can benefit. Logging in and out is so 1995.
Taken from:
https://arkaitzj.wordpress.com/2010/03/08/linux-add-user-to-a-group-without-logout/
So if you needed to get permissions for the cdrom
group you just added your user to:
newgrp cdrom
for example
So the steps would be:
#adduser my_user cdrom
and then
$newgrp cdrom
I've confirmed that it works.
A simple $groups
check from the CLI shows the user is in the group. And a quick execution with needed privileges from that group works.
No need to kill your windows and login and logout! Hope that helps others!
Additional Information (based on jytou's helpful comment): "[This] solution will work only for the current opened shell. If you have another shell open, you'll need to use the same command to take the changes into account."
Solution 2:
When adding a user to a new group, the user must log out and log back in for it to take affect. While a reboot will accomplish that, it should not be required.