Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Automatically add user to all groups?
Automatically add user to all groups?
I know to how to add a user to multiple groups. I know where to find the list of groups. I know where to find the list of groups used by the installer.
What I want to do is automatically add a user to all groups without having to manually type them out or spend half a day writing a script.
I know manually typing them out would only take a few minutes. I know a graphical user manager would work easily also but I want to do this without X installed.
Any way to do what I'm asking from the command line without a script and without manually typing the group names?
What I want to do is automatically add a user to all groups without having to manually type them out or spend half a day writing a script.
I know manually typing them out would only take a few minutes. I know a graphical user manager would work easily also but I want to do this without X installed.
Any way to do what I'm asking from the command line without a script and without manually typing the group names?
Re: Automatically add user to all groups?
The following may be a start:
Ther sure are zillions of other ways to do it e.g. using "join" and other helpers...
Code: Select all
$ echo usermod -a -G$(awk -F: 'NR>1{printf","}{printf$1}' /etc/group) SomeUserName
usermod -a -Groot,daemon,bin,sys,adm,tty,disk,lp,mail,news,uucp,man,proxy,kmem,dialout,fax,voice,cdrom,floppy,tape,sudo,audio,dip,www-data,backup,operator,list,irc,src,gnats,shadow,utmp,video,sasl,plugdev,staff,games,users,nogroup,input,systemd-journal,systemd-timesync,systemd-network,systemd-resolve,systemd-bus-proxy,crontab,netdev,ssl-cert,lpadmin,messagebus,avahi,scanner,Debian-exim,mlocate,ssh,avahi-autoipd,bluetooth,colord,geoclue,utempter,pulse,pulse-access,rtkit,saned,Debian-gdm,yeti,debian-tor,ruth,kvm,uml-net,wireshark,i2c SomeUserName
"I have a natural instinct for science" — DJ Trump.
"Vrijdag voor VT100!" — Yeti.
"There is no PLANET-B!" — ???
"Vrijdag voor VT100!" — Yeti.
"There is no PLANET-B!" — ???
Re: Automatically add user to all groups?
If I'm understanding your requirements correctly, you want to perform a repetitive task on variable and arbitrary data, and you're open to any solution, so long as it's not manual or automated?
Maybe have a look at sed?
Maybe have a look at sed?
Re: Automatically add user to all groups?
So you want one of us to spend/waste half a day for you?Jason_25 wrote:without having to manually type them out or spend half a day writing a script.
So, not a lot longer than making this post.Jason_25 wrote:I know manually typing them out would only take a few minutes.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
Re: Automatically add user to all groups?
What would it take, in terms of dollars to get an option added to the adduser command that would do this automatically? Failing that, what would it take, in terms of dollars for some non-lazy person to write this very boring script that checks all groups and then feeds them into the useradd command after asking the name of the user? Yes, I am completely capable of banging out a nice looking script that does this. No, I am not going to do this because I consider it an essential system command.
I consider any script or command that uses fixed groups "cheating" because it is not completely system agnostic.
Doesn't it seem like a shortcoming to have to manually do this or write a script? Yes this posting and procrastinating is taking a lot longer than it should but I really don't want to do this again. I have had to do it many times but this is the straw that broke the camel's back. I know others have been annoyed by this in the past and haven't bothered to post but I am doing the complaining for them this time.
If nothing else I will install an X based user manager and then uninstall it but I still hate this whole situation.
I consider any script or command that uses fixed groups "cheating" because it is not completely system agnostic.
Doesn't it seem like a shortcoming to have to manually do this or write a script? Yes this posting and procrastinating is taking a lot longer than it should but I really don't want to do this again. I have had to do it many times but this is the straw that broke the camel's back. I know others have been annoyed by this in the past and haven't bothered to post but I am doing the complaining for them this time.
If nothing else I will install an X based user manager and then uninstall it but I still hate this whole situation.
-
- Posts: 1100
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Automatically add user to all groups?
Here's one way...
But I can't imagine why you would want to do this...
Code: Select all
#!/bin/bash
grp_lst=`cat /etc/group | awk -F: '{print $1}'`
for grp in $grp_lst ; do
sudo usermod -a -G "$grp" "$1"
done
Re: Automatically add user to all groups?
Seems unlikely, since you can't even come up with an accurate order-of-magnitude estimate of the effort required to do so.Jason_25 wrote:Yes, I am completely capable of banging out a nice looking script that does this.
Re: Automatically add user to all groups?
Code: Select all
#!/bin/bash
#this will add a user for you without all the trouble
#run as root
#here is a tip - do not use $GROUPS as a variable
read -p "Type the requested user name" -n 20 -r
COLLECTED_GROUPS=$( cat /etc/group | cut -d ':' -f1 )
COLLECTED_GROUPS_PROCESSED=$(echo $COLLECTED_GROUPS | tr ' ' ',')
useradd $REPLY -M -G $COLLECTED_GROUPS_PROCESSED
- dilberts_left_nut
- Administrator
- Posts: 5346
- Joined: 2009-10-05 07:54
- Location: enzed
- Has thanked: 12 times
- Been thanked: 66 times
Re: Automatically add user to all groups?
There are a lot of groups on a standard system that an interactive user has no business being a member of.
AdrianTM wrote:There's no hacker in my grandma...
-
- Posts: 1100
- Joined: 2016-01-07 12:25
- Has thanked: 5 times
- Been thanked: 16 times
Re: Automatically add user to all groups?
I have to wonder why you even asked the question in the first place?? if you can use your ADDUSER_NOT_CRAP_VERSION (a two minute script) then why the need to ask someone else to do it for you? If it was simply to get this as a request for inclusion in the adduser package I sincerely hope it does not get in (I think the developers would have more sense).Jason_25 wrote:I call it ADDUSER_NOT_CRAP_VERSION.Code: Select all
#!/bin/bash etc...
Agreed.dilberts_left_nut wrote:There are a lot of groups on a standard system that an interactive user has no business being a member of.
-
- df -h | grep > 20TiB
- Posts: 1400
- Joined: 2012-10-06 05:31
- Location: /dev/chair
- Has thanked: 79 times
- Been thanked: 175 times
Re: Automatically add user to all groups?
And by implication the standard adduser binary is crap? Because you are too lazy to tackle the basic system-administration task of selecting groups for a user?Jason_25 wrote:I call it ADDUSER_NOT_CRAP_VERSION.
If adduser added new users to all groups by default it would be chaos, this is a task that is critical to system security and requires human intelligence behind the wheel.
If you have a lot of users to add at once, with the same groups, that's trivial to automate... the tool to do it is known as sh. As you well know.
But as a default behaviour of adduser? No. No way in hell. Horrible idea.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
-
- Posts: 162
- Joined: 2016-01-10 16:58
Re: Automatically add user to all groups?
I need to add several new users to the PCby steve_v » If adduser added new users to all groups by default it would be chaos, this is a task that is critical to system security and requires human intelligence behind the wheel.
is this what this code does ? :
I was searching the forum and wanting to learn more about using the adduser command is this script safe to use ?Jason_25 wrote:I call it ADDUSER_NOT_CRAP_VERSION. These are the highs and lows of free software usage. On one hand you can do anything you want, on the other hand you don't want to do anything.Code: Select all
#!/bin/bash #this will add a user for you without all the trouble #run as root #here is a tip - do not use $GROUPS as a variable read -p "Type the requested user name" -n 20 -r COLLECTED_GROUPS=$( cat /etc/group | cut -d ':' -f1 ) COLLECTED_GROUPS_PROCESSED=$(echo $COLLECTED_GROUPS | tr ' ' ',') useradd $REPLY -M -G $COLLECTED_GROUPS_PROCESSED
I also have been looking at this :
Code: Select all
man adduser
Code: Select all
man usermod
So is this script safe to try ? How would I be able to reverse it
if I do not like the results ?
From what steve_v says I am thinking it is not a good script to use but hopeing it is no problem to ask. I assume the administration and moderators would not allow any scripts that are harmful or could cause problems to my computer but there is some comments in this thread that are confusing and it is not clear what the script does.
Also how do I use it ?
Thank you in advance.
-
- df -h | grep > 20TiB
- Posts: 1400
- Joined: 2012-10-06 05:31
- Location: /dev/chair
- Has thanked: 79 times
- Been thanked: 175 times
Re: Automatically add user to all groups?
At a cursory glance, it collects all groups from /etc/groups and adds a new user with membership of those groups. Most likely not at all what you want.jibberjabber wrote: I need to add several new users to the PC
is this what this code does ? :
Find the commands you need to add a user with the groups you want (man pages etc), then, if you have a bunch of users the same to do, wrap it in e.g. a for loop with a list of users. for user in <list>; do <something>; done
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Re: Automatically add user to all groups?
No.jibberjabber wrote:I need to add several new users to the PC
is this what this code does ?
Bless you for asking this question.jibberjabber wrote:is this script safe to use ?
"Safe" in the sense that it won't erase your hard drive, yes; but it lacks both elegance and error-checking. More to the point, as others have already pointed out, it's also kind of pointless. I'm sure the OP imagines that it has some value, but that value is not at all obvious to others. Then too, depending on one's configuration, the script could plausibly create a number of troubling (and entirely optional) problems.
Bless youjibberjabber wrote:I also have been looking at this :andCode: Select all
man adduser
Code: Select all
man usermod
That's not a safe assumption to make.jibberjabber wrote:I assume the administration and moderators would not allow any scripts that are harmful or could cause problems to my computer
Based on what you've said, adduser is the right tool for the job you're trying to do. And there is really no benefit to trying to write a script for it; you won't save (m)any keystrokes by automating it.
Re: Automatically add user to all groups?
no, and no.jibberjabber wrote:I need to add several new users to the PCby steve_v » If adduser added new users to all groups by default it would be chaos, this is a task that is critical to system security and requires human intelligence behind the wheel.
is this what this code does ? :
I was searching the forum and wanting to learn more about using the adduser command is this script safe to use ?
I also have been looking at this :andCode: Select all
man adduser
Code: Select all
man usermod
as was pointed out already, this script does something very questionable.
it is hard to perceive how this could even be useful on one particular setup, but it definitely is NOT something you want to suggest/recommend to others.
you should use the tools that are usually present on any linux distro, and take the time to understand what you're doing and how to achieve it.