1

Can someone please tell me how to logout and log back in again via the command line so that I can apply a new group's settings to a user. To put this in perspective, assume that I am currently logged in as testuseraccount, and then I issue the commands below into the terminal.

su
usermod -aG sudo testuseraccount

So I believe by typing su this logs me into root (but just within the shell). So how do I logout of root, then logout of testuseraccount & sign back in (in order to apply the sudo group to testusersaccount) via the terminal?

marked as duplicate by Gilles 'SO- stop being evil', cuonglm, G-Man Says 'Reinstate Monica', Michael Homer, Anthon Jun 23 '15 at 3:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I have tried answering as many aspects of the question as I could see, with my answer below. If they do not cover your main question please rephrase to make it more clear. – Ned64 Jun 18 '15 at 11:45
3

You cannot change existing processes' group id, which means one way is to restart them. Child processes inherit the parent's group id, so programs you start in your deskop environment (menu...) you cannot influence.

Within a given shell, use the newgrp command to start a new shell with the new effective group id:

> id
uid=1000(user) gid=100(users) groups=100(users),92(audio)
> newgrp audio
> id
uid=1000(user) gid=92(audio) groups=92(audio),100(users)

Any process started from this shell will have the new effective group id (audio in this case).

If you have added a new user to a group this will again take effect after the user starts a new process.

As a consequence, if you wish to start a new X (graphical login) session, you need to exit the previous session completely, then start the new session by logging in. Logging back in without interaction after logging out is not intended to be possible by the login screen (by XDM/GDM/KDM) unless passwordless login is enabled (which no-one recommends). One reason is that during logout, all processes of the user are to be terminated, so no process is left to initiate logging you in.

Workarounds may be created but will be "ugly", I expect.

  • Ok, this is a little bit over the top of me. I will just assume its faster to reboot my machine for the settings to take affect – john smith Jun 18 '15 at 11:47
  • A reboot is not necessary - just log out and log back in! For a very fast logout (without saving any open files etc.) you can issue kill -HUP -1 in a terminal AS THE USER (not root). – Ned64 Jun 18 '15 at 11:50
  • Ok thanks. I will do it on the GUI when I test it again tonight. – john smith Jun 18 '15 at 11:51
  • What is it that gave you the impression that asker has an [XGK]DM started from boot? Why should asker not just exit X and enter it again from its parent shell? – mikeserv Jun 19 '15 at 5:56
  • @mikeserv While I do not know the things that were not specifically mentioned, it seems to be a standard installation, and thereby has in all likeliness XDM or a relative (cf. Ockham's Razor). Let's see what John says. – Ned64 Jun 19 '15 at 8:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.