Add existing user into an existing group

Pre: no gpasswd/adduser

there is just usermod can be used, also there is no -a option for usermod.

How should I add a user into a group?

"usermod -G group user"

1 Like

edit the /etc/group file and you will be good to go.

Yes, vi is what I would use. Here is something that should work if scripting is a requirement. I misunderstood the question in my first answer.

usermod -G $(groups user| sed -e 's/.*: *//' -e 's/  */,/g'),group user

THAT took me 17 minutes to decipher. Now I know why I love VEE EYE :smiley:

But, at work I usually use a combination of cut and tr to achieve the same; switching to this from now on. Thanks!