viagra
phentermine

Posts Tagged ‘add’

Adding Batches of Users to Groups

Friday, February 1st, 2008

You need to add a whole bunch of users to a group.

Paste your list of login names directly into /etc/group.

Here’s a quick way to generate a list of users to add to /etc/group. This depends on having a UID numbering scheme already in place, so that you can easily sort out selected groups of users. Let’s add some Trainers to a group:

$ awk -F: ‘($3 >= 1050) && ($3 <=1060) { print $1}' /etc/passwd | tr '\n' ','
bcool,bkind,frnow,kthxbye,oknodo,

Now copy and paste into /etc/group.

What if you do not have a nice, tidy, organized UID scheme? This is where the GECOS fields come in handy. Go back and pick one for entering some kind of label. The “other” field is best, because users are blocked from changing it. Where is this “other” field? It’s inside the “full name,” or GECOS, field which contains five comma-delimited fields. It looks like this:

bcool:x:1300:1300:Bob Cool,,,,trainer:/home/bkind:/bin/bash
bkind:x:1055:1055:Bev Kind,,,,trainer:/home/bkind:/bin/bash

Once you’ve added the labels, grep and awk can easily fetch these users for you:

$ cat /etc/passwd | grep trainer | awk -F: ‘{ print $1}’ | tr ‘\n’ ‘,’
bkind,bcool,

Adding New Users in Batches

Friday, February 1st, 2008

If you want to be able to add several users at once, rather than having to enter each one individually, use the mass_useradd script. It’s a shell script, so it should run just about anywhere. You’ll also need mass_passwd. Store the two scripts in the same directory. You should also install the pwgen utility, for generating passwords. You’ll need a colon-delimited text list of logins and usernames in this format:

(more…)