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.

  • 1
    usermod -a -G groupname username doesn't work on raspbian?
    – jimmij
    Commented Jun 30, 2016 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
    Commented Jun 30, 2016 at 6:50
  • 1
    Without -a groups are overwritten, this is most of the time not what you want to do, unless you create new user.
    – jimmij
    Commented Jun 30, 2016 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
    Commented Jun 30, 2016 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. Commented Jun 30, 2016 at 10:49

1 Answer 1


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 a user who is currently logged in (including yourself), they must logout and login again for the change to take effect. (Under some circumstances a reboot may be required. Check id after logging in again to see if the new group is present.)

  • 4
    I had to use -G flag instead of G alone Commented May 4, 2018 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .