Skip to content

Instantly share code, notes, and snippets.

@dash17291
Forked from zipizap/gist:4976977
Created May 6, 2013 10:46
Show Gist options
  • Save dash17291/5524436 to your computer and use it in GitHub Desktop.
Save dash17291/5524436 to your computer and use it in GitHub Desktop.
# How to add user into group, and make changes take effect *without logout/login*: the *newgrp* command
#
# Do note that this method will only update the groups, in the current shell session (and its child-processes).
# New shell sessions will not have the groups updated - either use this method to update the groups in each shell
# session, or logout/login to make the group update permanent by default
#
# In short:
# $ sudo adduser user_x my_grp
# $ newgrp my_grp && newgrp
#
# Here is the rundown annotated:
#Add user_x into group sambashare
user_x@stest:~$ sudo adduser user_x sambashare
user_x@stest:~$ id
uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout)
#changes did not take effect
user_x@stest:~$ newgrp
user_x@stest:~$ id
uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout)
#changes still did not take effect
user_x@stest:~$ newgrp sambashare
user_x@stest:~$ id
uid=1001(user_x) gid=115(sambashare) groups=1002(user_x),20(dialout),115(sambashare)
#changes *did* take effect now:
# - changed 'gid=115(sambashare)'
# - appended '115(sambashare)'
user_x@stest:~$ newgrp
user_x@stest:~$ id
uid=1001(user_x) gid=1002(user_x) groups=1002(user_x),20(dialout),115(sambashare)
#reestablished 'gid=1002(user_x)'
# all done now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment