'sudo id -G <username>' vs 'id -G' issue

Ralf Mardorf silver.bullet at zoho.com
Wed Nov 2 21:19:23 UTC 2016


I need to run a script with root privileges. One thing this script
could do, is adding a user to a new group. Sometimes the script doesn't
know, if this is already active for the user. IOW the user is already
member of the group, but didn't log out and in again, resp. didn't
restart the display manager. Unfortunately id, groups and getent, even
when running with 'sudo -u ubuntu-mate' fail.

An example
ubuntu-mate at ubuntu-mate:~$ id -G
999 4 24 27 30 46 123 132
ubuntu-mate at ubuntu-mate:~$ sudo id -G ubuntu-mate
999 4 24 27 30 46 123 132 1000

In this case the script should offer to run
'systemctl restart lightdm', since '1000' is quasi inactive, but since
the script runs with root privileges '1000' already is shown, so the
script can't decide to offer running 'systemctl restart lightdm'.

Is there a way to get the real state?

Or is there a way to 'activate' the group by something less obtrude
than restarting the display manger, so that the script doesn't need to
check if it should offer an option, but instead always could runs this
less obtrude process, that doesn't terminate possible important
processes, the user needs at this moment?


More information about the ubuntu-users mailing list