adduser to multiple groups

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?

1 Answer

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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like