How do I add a user to a group.

This is on a system with no root password and only a single user pi with sudo privileges.

usermod seems to have been designed to make this as difficult as possible.

  • usermod -a -G groupname username doesn't work on raspbian? – jimmij Jun 30 '16 at 6:11
  • @jimmij I think I was missing the -a I was going from a book on Ubuntu which said -G didn't work if the user is logged in, and it didn't seem to work. – Milliways Jun 30 '16 at 6:50
  • Without -a groups are overwritten, this is most of the time not what you want to do, unless you create new user. – jimmij Jun 30 '16 at 6:56
  • you use -G when adding new user and want it to be a member of supplementary group along with primary group , otherwise you can use usermod with -aG – Ijaz Ahmad Khan Jun 30 '16 at 7:39
  • The usermod works whether the user is logged in or not, however it only affects new sessions; current sessions don't pick up the change. So after the usermod you should logout and login again. – Stephen Harris Jun 30 '16 at 10:49

You can use usermod or edit the group file directly

# usermod -a -G ${group} ${user}

# vi /etc/group

Just remember group changes do not always propagate to active sessions. If you are changing your own user logout and then log back in.

  • 1
    I had to use -G flag instead of G alone – Jules Randolph May 4 '18 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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