3

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
  • 75
  • 1
  • 7

1 Answers1

6

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.

Benny
  • 4,920
  • thats what im trying to avoid - i want to add the user into 2 groups with the adduser command as is my question – Erres Oct 18 '16 at 12:43
  • 3
    useradd -G group1,group2 username Each group name is separated by a comma, with no intervening spaces. – Benny Oct 18 '16 at 13:17