On Sun, Dec 20, 2020 at 05:03:40PM +0000, Andy Smith wrote: > On Sun, Dec 20, 2020 at 11:32:33AM +0000, mick crane wrote: > > I noticed that if you add yourself to sudo group in /etc/group you > > have to logout and log back in for it to be noticed. > > If you don't want to log out of the shell you can do this: > > $ exec sg sudo "newgrp $(id -ng)"
Of course this only gives you the new privileges in that one shell, not in all of your other windows, not in any other programs that are already running, and not in any future programs that are invoked as a child of an already-running process (such as your window manager). > The "exec" causes what follows to replace the current shell. Without > this you'd end up with two extra shells running and would have to > "exit" three times to close them. > You can just do "su - $USER" but this will ask you for your > password. I sometimes use exec su - "$LOGNAME" if I only need the new privileges in a single shell, and am willing to defer the full logout/login cycle. "$USER" will work as a substitute for "$LOGNAME" in a typical interactive shell, but it's worth knowing that this is not a standard variable under Linux, and may not always be available in all execution environments.