adduser to multiple groups

7,949

You can do it with: usermod, like this:

usermod -a -G group1,group2 username

Where username is the user you want to modify and group1 and group2 are the new groups you want that user to join. Running the command without the -a argument will remove that user from all groups except group1 and group2.

Share:
7,949

Related videos on Youtube

Erres
Author by

Erres

Updated on September 18, 2022

Comments

  • Erres
    Erres over 1 year

    I'm trying to add a user into two groups when creating a new account. Now I use this command;

    adduser --gid 33 --home /home/wwwroot/domain.com --force-badname %USER%
    

    and then

    usermod -a -G group user (let say GID is 1008)
    

    I do this for each new user on a webserver to use SFTP (GID 1008).

    What i want to do is this:

    adduser + group + group
    
    adduser --gid 33,1008 --home /home/wwwroot/domain.com --force-badname %USER%
    

    Unfortunately this doesn't work this way.

    Any suggestions?

  • Erres
    Erres over 7 years
    thats what im trying to avoid - i want to add the user into 2 groups with the adduser command as is my question
  • Benny
    Benny over 7 years
    useradd -G group1,group2 username Each group name is separated by a comma, with no intervening spaces.