Quickly add a new user to all groups the default user is in

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,568
Reaction score
1,285
Credits
11,462
Hi everyone! Hope you're all having a nice life! :)

So, I read this https://www.commandlinefu.com/comma...new-user-to-all-groups-the-default-user-is-in and the code seems pretty simple, however, I do have one question
Code:
$ awk -F: '/^.+user1/{print $1}' /etc/group | xargs -n1 sudo adduser user2
This is straightforward, but the one thing that bugs me is the fact that if you take a look at /etc/group, you'll find there's a group called user1, so I was wondering whether it is a good idea adding user2 to group user1. Or am I getting all wrong and that won't happen? I wanted to ask in that site, but then I noticed there's a lot of what appears to be spam there, so I figured my question might stay unanswered. What do you think?

EDIT: Ok. I think just figured it out :) I ran the first part only
Code:
awk -F: '/^.+user1/{print $1}' /etc/group
and this was the output:
Code:
adm
cdrom
sudo
dip
plugdev
lpadmin
sambashare
So I take it user2 won't be part/added to group user1, but only those in that output, is that correct?
 
Last edited:

Members online


Top