After adding a group, logout+login is not enough in 18.04?
Solution 1
The command loginctl terminate-user $USER
worked for me. You probably shouldn't run this when logged in though as it will kill all your processes.
Solution 2
When "logging out" of the default desktop in ubuntu 18.04, some of the user's processes are not terminated immediately, but linger around. These are (observed by another user):
$ ps axu | grep ^ludwig
ludwig 26508 0.3 0.2 77052 8308 ? Ss 23:32 0:00 /lib/systemd/systemd --user
ludwig 26509 0.0 0.0 261776 2968 ? S 23:32 0:00 (sd-pam)
ludwig 26691 0.2 0.3 381288 12204 ? S<l 23:32 0:00 /usr/bin/pulseaudio --start --log-target=syslog
ludwig 27352 0.0 0.0 49796 3756 ? Ss 23:33 0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
When logging back in before these processes exit voluntarily, then no new login session is created, but the old one is reused. This is the reason why the new group membership is not visible, it is still the same old login session.
A workaround to avoid rebooting is to wait ~20 seconds after logging out and only then logging back in. The processes exit somewhere between 10 and 20 seconds after logging out.
Edit: As reported in the comments below, sometimes the lingering processes will not quit even with waiting, and after logging back in, the group memberships have not been updated. I found that in this case it helps to
ps axu | grep ^ludwig | awk '{print $2}' | xargs kill -9
Replace ludwig
with your user name. This kills all processes that belong to you. Use only when you're sure you have all your data in all your open programs saved.
Solution 3
A workaround in the current shell is to run "su " to have the new group without having to reboot.
As I said, this trick has to be applied to each shell. That's not global.
Related videos on Youtube
Ludwig Schulze
Updated on September 18, 2022Comments
-
Ludwig Schulze over 1 year
In ubuntu 18.04 with default desktop, behaviour of logout/login has changed:
Previously on an Ubuntu system, when I find that I need to add my user id to some group, it was sufficient to
sudo adduser ludwig docker # adds me to group docker
and then I had to logout and login again to make the group change effective.
I notice that with Ubuntu 18.04, after adding the group and logging out and back in, the list of effective groups is still unchanged.
As a workaround I rebooted the system, which is inconvenient (requires making the right selection in grub and re-entering the disk encryption password).
- Why is the behaviour now like this?
- Can I do something else short of rebooting?
(I know I can ssh into localhost and get the correct groups in the ssh session only. This is also too inconvenient.)
-
Terrance almost 6 yearsI tested
sudo usermod -a -G group user
in 18.04 and logged out and back in and it worked. -
Ludwig Schulze almost 6 yearsalso with default desktop?
-
Terrance almost 6 yearsYou mean like the difference between GNOME, Xubuntu, Kubuntu, etc.? If you mean that GNOME is the default, then no, I don't run GNOME. But the command should be the same regardless of desktop environment as this is core password / group stuff that should be the same across all DEs.
-
Terrance almost 6 yearsOK, I just installed GNOME for testing, and
sudo usermod -a -G groupname username
worked fine there as well. Logged out and back in and my change was there. -
Ludwig Schulze almost 6 yearsI see. @Terrance you are not using the default desktop. The default desktop is named "ubuntu". I know it is based on gnome, but I understand that "gnome" is another desktop. "ubuntu" was altered to resemble unity.
-
niknah almost 6 yearsThis was my problem. But the processes did not go away after logging out and waiting. I had to kill the "systemd --user" process, and run "sudo systemctl daemon-reexec". And also kill all the dbus processes cause restarting systemd screws up dbus. Needed to restart network manager too. "systemctl restart network-manager" Maybe restart everything that depends on dbus/systemd
-
Ludwig Schulze almost 6 years@niknah Oh that's bad. Sounds like it would be easier to just reboot in your case. Thanks for letting everyone know that it can be more difficult.
-
Ludwig Schulze almost 6 years@niknah I ran into the same problem as you today. After logging out and waiting, some processes just would not quit. I found a workaround and will update this answer.
-
AqD about 5 yearsconfirmed working on Ubuntu 18.04. Much easier than ps&grep!
-
Ludwig Schulze almost 5 yearsAgreed, this is shorter to type than my own solution. It also helps on ubuntu 19.04. Upvoted and accepted instead of my own solution.
-
xdevs23 over 4 yearsThis can be used to fix adb not recognizing devices after adding the user to adbusers aka
sudo usermod -a -G adbusers $USER
. Then you can dosu $USER
andsudo adb kill-server && adb start-server
to fix the issue -
perennial_noob over 2 yearsIf you update your answer to
loginctl terminate-user ${USER}
you shouldn't need the instruction to replace the user esp since the OP is about their own user. Or even$(whoami)
-
Aquarius Power over 2 yearsworking 20.04, and it WILL terminate user sending you to login :)