Add user to group, and make changes take effect *without logout/login* using *newgrp* This solution is very limited - it will only update the groups in the current shell session. New shells sessions will not have the groups updated - you can update them manually with this method, or better yet, you can logout/login so that the group update is ma…
# 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