matt_k
matt_k

Reputation: 4459

Add user to group but not reflected when run "id"

R creates a group called staff and I want to be able to update packages without starting R as sudo. So I added myself to staff using:

sudo usermod -G adm,dialout,cdrom,plugdev,lpadmin,admin,sambashare,staff matt

(side question is there a way to add yourself to a group without listing every other group you're a member of?)

If i check /etc/groups i see

staff:x:50:matt

and the same for /etc/shadow

staff:*::matt

however if i run groups or id i'm not a member of staff. Also, I can't make changes to anything in /usr/local/lib/R.

Upvotes: 29

Views: 35047

Answers (5)

Aviv
Aviv

Reputation: 14477

Explanation: The operation succeeded - that's why your name appears in the right linux files on /etc/passwd & /etc/group but as soon as you open a new terminal process the bash will be updated with this setting and you can perform id matt as well.

Clarification: You added yourself to additional group so you should have used append option -a (and not editing the all bunch of groups names to your user).

sudo usermod -aG staff matt

Upvotes: 0

kiiwii
kiiwii

Reputation: 7913

https://superuser.com/questions/272061/reload-a-linux-users-group-assignments-without-logging-out

check that out ~

both

newgrp groupname

OR

su - username

will do the trick well ~

Upvotes: 19

voidstate
voidstate

Reputation: 7990

I know the original question is for Linux but OSX users can do the same with this command:

sudo dseditgroup -o edit -a newusertoadd -t user grouptobeaddedto

Upvotes: 0

lxop
lxop

Reputation: 8595

In answer to your side question, yes you can add a user to a group without listing them all. If you run a Debian based system, you can do it with

sudo adduser matt staff

The adduser utility is just a friendly wrapper around useradd/usermod etc.

If you don't have the adduser utility, you can still do it with usermod:

sudo usermod -a -G staff matt

The -a flag means append (as opposed to overwrite).

Upvotes: 5

freiheit
freiheit

Reputation: 5054

Did you log the "matt" account out and back in after running the sudo usermod command? Changes to the groups a user is in under unix only take affect at login time.

Upvotes: 56

Related Questions