<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer Support &#187; Users / Groups</title>
	<atom:link href="http://www.xiitec.com/blog/category/system-administration/unix/users-group/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xiitec.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 30 Dec 2009 08:40:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Disk Quotas</title>
		<link>http://www.xiitec.com/blog/2008/02/01/using-disk-quotas/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/using-disk-quotas/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 22:20:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[disk quotas]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=82</guid>
		<description><![CDATA[If you want to limit the amount of disk storage any user can consume. Most sites have a few disk hogs around, who just love to fill the disk with their MP3 collections and downloaded sitcoms, use the Linux Disk Quota package. This contains several components, including quota, edquota, quotacheck, and repquota.

First, edit /etc/fstab and [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to limit the amount of disk storage any user can consume. Most sites have a few disk hogs around, who just love to fill the disk with their MP3 collections and downloaded sitcoms, use the Linux Disk Quota package. This contains several components, including <code>quota</code>, <code>edquota</code>, <code>quotacheck</code>, and <code>repquota</code>.</p>
<p><span id="more-82"></span></p>
<p>First, edit <code>/etc/fstab</code> and select the partitions to enable quotas. Your choices are <code>usrquota</code>, for individual users, or <code>grpquota</code>, for putting quotas on groups. It&#8217;s okay to have both:</p>
<blockquote><p>/dev/hda6  /      ext3 defaults                    0   1<br />
/dev/hda7  /home  ext3 defaults,usrquota,grpquota  0   2</p></blockquote>
<p>Now remount the filesystem:</p>
<blockquote><p># mount -o remount /home</p></blockquote>
<p>Quota&#8217;s init script will run <code>quotacheck,</code> which will examine the installation, create a database of disk usage, and create quota files.</p>
<p>Next, assign a quota to a user. This opens a configuration file in your default editor:</p>
<blockquote><p># edquota -u vhenson<br />
Disk quotas for user vhenson (uid 1550):<br />
Filesystem  blocks   soft  hard   inodes   soft   hard<br />
/dev/hda7   550466    0     0      47466    0      0</p></blockquote>
<p>Soft limits allow a grace period, with warnings to the user. Hard limits cut them off immediately. To set limits, simply edit the file:</p>
<blockquote><p># edquota -u vhenson<br />
Disk quotas for user vhenson (uid 1550):<br />
Filesystem  blocks  soft    hard     inodes   soft   hard<br />
/dev/hda7   550466  650000  700000   47466    0      0</p></blockquote>
<p>Blocks are always 1024 bytes, so 650,000 blocks is about 665 megabytes.</p>
<p>Save and close the file, and verify that the quota is in effect:</p>
<blockquote><p># quota vhenson<br />
Disk quotas for user vhenson (uid 1550): 650000  700000</p></blockquote>
<p>To assign a quota to a group use:</p>
<blockquote><p># edquota -g engineers</p></blockquote>
<p>Note that if a single greedy user in a group uses up the group quota, it&#8217;s too bad for the rest of the group—it&#8217;s all gone.</p>
<p>This invokes the default editor, for setting the grace period for soft limits on the entire filesystem:</p>
<blockquote><p># edquota -t<br />
Grace period before enforcing soft limits for users:<br />
Time units may be: days, hours, minutes, or seconds<br />
Filesystem    Block grace period    Inode grace period<br />
/dev/hda3     7days                 7days</p></blockquote>
<p>You can use one &#8220;prototype&#8221; user as the model for new users:</p>
<blockquote><p># edquota -p vhenson dnorth</p></blockquote>
<p>or for a whole bale of users:</p>
<blockquote><p># edquota -p vhenson `awk -F: &#8216;$3 &gt; 999 {print $1}&#8217; /etc/passwd`</p></blockquote>
<p>Or you can list several at once:</p>
<blockquote><p># edquota -p vhenson dnorth jvesperman sanvin</p></blockquote>
<p>You&#8217;ll doubtless want to keep an eye on things. This repquota command gives a system-wide snapshot of current usage:</p>
<blockquote><p># repquota -a</p></blockquote>
<p>For a specific filesystem, use:</p>
<blockquote><p># repquota /home</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/using-disk-quotas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Granting Limited Rootly Powers with sudo</title>
		<link>http://www.xiitec.com/blog/2008/02/01/granting-limited-rootly-powers-with-sudo/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/granting-limited-rootly-powers-with-sudo/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 21:25:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=81</guid>
		<description><![CDATA[If you would like to delegate some system administration chores to other users, or set up an extra layer of safety for your own root chores—but you want to do it in a way that uses only limited rootly powers, and does not give away root&#8217;s password, use sudo. sudo grants limited root powers to [...]]]></description>
			<content:encoded><![CDATA[<p>If you would like to delegate some system administration chores to other users, or set up an extra layer of safety for your own root chores—but you want to do it in a way that uses only limited rootly powers, and does not give away root&#8217;s password, use <code>sudo</code>. <code>sudo</code> grants limited root powers to specific users for specific tasks, logs activity, and does not give away root&#8217;s password.</p>
<p><span id="more-81"></span></p>
<p>Let&#8217;s say that you have a user, <code>jhaugh</code>, upon whom you wish to bestow full rootly powers. Because <code>sudo</code> users use their own passwords, root&#8217;s password is protected. Edit <code>/etc/sudoers</code> with <code>visudo</code>—it will open in your default text editor:</p>
<blockquote><p># visudo<br />
# sudoers file.<br />
#<br />
# This file MUST be edited with the &#8216;visudo&#8217;<br />
# command as root.<br />
# See the man page for details on how to write<br />
# a sudoers file.<br />
#<br />
# Host alias specification<br />
# User alias specification<br />
# Cmnd alias specification<br />
# User privilege specification</p>
<p>root    ALL=(ALL) ALL</p></blockquote>
<p>First, set up a host alias:</p>
<blockquote><p>Host_Alias LOCALHOST= localhost</p></blockquote>
<p>Under the &#8220;User privilege specification&#8221; line, you can add individual users:</p>
<blockquote><p>jhaugh    ALL=(ALL) ALL</p></blockquote>
<p>This gives jhaugh root powers for everything on the system and on all connected machines. Now say you have another user, tgwynne, who needs root privileges only on the local machine. Add the following line for this user:</p>
<blockquote><p>tgwynne    LOCALHOST = ALL</p></blockquote>
<p>Adding to your delegation of minions is msmith, who is allowed only to shut down the local machine:</p>
<blockquote><p>msmith    LOCALHOST = /sbin/shutdown, /sbin/halt</p></blockquote>
<p>This grants groups of ordinary users shutdown privileges on their own machines:</p>
<blockquote><p># Host alias specification<br />
Host_Alias LOCALHOST= localhost<br />
# User alias specification<br />
User_Alias    USERS = tgwynne, msmith, jhaugh, \<br />
abyron, jwinters</p>
<p># Cmnd alias specification<br />
Cmnd_Alias  SHUTDOWN = /usr/sbin/shutdown, /usr/sbin/halt, \<br />
/usr/sbin/reboot, /usr/sbin/poweroff</p>
<p># User privilege specification<br />
USERS    LOCALHOST = SHUTDOWN</p></blockquote>
<p>To execute a sudo command, users do this:</p>
<blockquote><p>$ sudo /usr/sbin/halt</p></blockquote>
<p>They will be prompted for their passwords, then the command will execute. Users can check which commands they are authorized for with the following command:</p>
<blockquote><p> $ sudo -l</p>
<p>User jhaugh may run the following commands on this host:<br />
(ALL) ALL</p></blockquote>
<p>sudo logs all errors to the syslog, and tattles to root:</p>
<blockquote><p>$ sudo /usr/sbin/halt<br />
carla is not in the sudoers file.  This incident will be reported.</p></blockquote>
<p>Groups of servers can be defined, and users can be given privileges to the groups:</p>
<blockquote><p># Host alias specification<br />
Host_Alias    FILESERVERS = host1, host2, host3<br />
# User alias specification<br />
User_Alias    FILESERVADMINS = jhaugh, abyron, jwinters<br />
# Cmnd alias specification<br />
Cmnd_Alias    FILEUTILS = /bin/chgrp, /bin/chmod, \<br />
/bin/chown, /bin/cp, /bin/dd, /bin/df, \<br />
/bin/dir, /bin/dircolors, /bin/du, /bin/install, \<br />
/bin/ln, /bin/ls, /bin/mkdir, /bin/mkfifo, \<br />
/bin/mknod,bin/mv, /bin/rm, /bin/rmdir, \<br />
/bin/shred, /bin/touch, /bin/vdir sync<br />
# User privilege specification<br />
FILESERVADMIN     FILESERVERS = FILEUTILS</p></blockquote>
<p><code>sudo</code> can also be used to let users execute scripts, such as backup scripts. Be very careful with scripts, or any command that gives shell access or invokes a text editor, because these may allow users to escalate their privileges. You can try to restrict sudo users to RJOE, which is a restricted editor that cannot invoke a shell, but it&#8217;s better to be careful with how you delegate rootly chores in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/granting-limited-rootly-powers-with-sudo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Batches of Users to Groups</title>
		<link>http://www.xiitec.com/blog/2008/02/01/adding-batches-of-users-to-groups/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/adding-batches-of-users-to-groups/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 21:03:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[batches]]></category>
		<category><![CDATA[groups]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=80</guid>
		<description><![CDATA[You need to add a whole bunch of users to a group.
Paste your list of login names directly into /etc/group.
Here&#8217;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. [...]]]></description>
			<content:encoded><![CDATA[<p>You need to add a whole bunch of users to a group.</p>
<p>Paste your list of login names directly into <code>/etc/group</code>.</p>
<p>Here&#8217;s a quick way to generate a list of users to add to <code>/etc/group</code>. This depends on having a UID numbering scheme already in place, so that you can easily sort out selected groups of users. Let&#8217;s add some Trainers to a group:</p>
<blockquote><p>$ awk -F: &#8216;($3 >= 1050) &#038;&#038; ($3 <=1060)  { print $1}' /etc/passwd | tr '\n' ','<br />
bcool,bkind,frnow,kthxbye,oknodo,</p></blockquote>
<p>Now copy and paste into <code>/etc/group</code>.</p>
<p>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 &#8220;other&#8221; field is best, because users are blocked from changing it. Where is this &#8220;other&#8221; field? It&#8217;s inside the &#8220;full name,&#8221; or GECOS, field which contains five comma-delimited fields. It looks like this:</p>
<blockquote><p>bcool:x:1300:1300:Bob Cool,,,,trainer:/home/bkind:/bin/bash<br />
bkind:x:1055:1055:Bev Kind,,,,trainer:/home/bkind:/bin/bash</p></blockquote>
<p>Once you&#8217;ve added the labels, grep and awk can easily fetch these users for you:</p>
<blockquote><p>$ cat /etc/passwd | grep trainer | awk -F: &#8216;{ print $1}&#8217; | tr &#8216;\n&#8217; &#8216;,&#8217;<br />
bkind,bcool,</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/adding-batches-of-users-to-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Masses of Passwords</title>
		<link>http://www.xiitec.com/blog/2008/02/01/changing-masses-of-passwords/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/changing-masses-of-passwords/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 20:56:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[batches]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[passwords]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=79</guid>
		<description><![CDATA[As part of your routine security policy, you would like to periodically be able to easily change batches of passwords. Or your network may have been compromised, so you want to change all the passwords yourself and not leave it up to your users.
Use the mass_passwd script. It lets you select batches of users in [...]]]></description>
			<content:encoded><![CDATA[<p>As part of your routine security policy, you would like to periodically be able to easily change batches of passwords. Or your network may have been compromised, so you want to change all the passwords yourself and not leave it up to your users.</p>
<p>Use the mass_passwd script. It lets you select batches of users in three different ways:</p>
<blockquote><p># mass_passwd<br />
username1<br />
username2<br />
&#8230;<br />
# mass_passwd -g<br />
groupname<br />
groupname<br />
&#8230;<br />
# mass_passwd -a</p></blockquote>
<p>The first method uses a simple space-delimited list of logins.</p>
<p>The second method changes the passwords of users belonging to the named groups.</p>
<p>The third method changes every password in <code>/etc/passwd</code>.</p>
<p>Then <code>mass_passwd</code> generates a separate file for each user, containing their new login names and passwords and whatever instructions or policies you choose to include. This is designed to make it easy to print a separate instruction sheet for each user.</p>
<p>You may do a dry run with the -n flag:</p>
<blockquote><p># ./mass_passwd -v -g -n usergroup<br />
generating password for dawns&#8230;..teivuphu<br />
generating password for nikitah&#8230;..kohfahsh<br />
2 password(s) reset &#8211; see /root/mass_passwds/mass_passwd.log</p></blockquote>
<p>No passwords are changed; this just lets you test-drive your options before committing to any changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/changing-masses-of-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding New Users in Batches</title>
		<link>http://www.xiitec.com/blog/2008/02/01/adding-new-users-in-batches/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/adding-new-users-in-batches/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 20:44:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[batches]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=78</guid>
		<description><![CDATA[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&#8217;s a shell script, so it should run just about anywhere. You&#8217;ll also need mass_passwd. Store the two scripts in the same directory. You should also install the pwgen utility, for [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to be able to add several users at once, rather than having to enter each one individually, use the <code>mass_useradd</code> script. It&#8217;s a shell script, so it should run just about anywhere. You&#8217;ll also need <code>mass_passwd</code>. Store the two scripts in the same directory. You should also install the <code>pwgen</code> utility, for generating passwords. You&#8217;ll need a colon-delimited text list of logins and usernames in this format:</p>
<p><span id="more-78"></span></p>
<blockquote><p>login<br />
:<br />
firstname<br />
lastname</p></blockquote>
<p>You may also include additional GECOS data, like this:</p>
<blockquote><p> dawns:Dawn Marie Schroder,,123-4567,trainers</p></blockquote>
<p>Then invoke the <code>mass_useradd</code> script. It creates entries in <code>/etc/passwd</code>, <code>/etc/group</code>, and <code>/etc/shadow</code>; home directories; personal login groups; and passwords that expire at first use.</p>
<p>This tells <code>mass_useradd</code> to use the list of new users in newusers and to overwrite or create the output file <code>newlogins.txt</code>:</p>
<blockquote><p># sh mass_useradd &lt; newusers &gt; newlogins.txt</p></blockquote>
<p>This appends the new logins and passwords to <code>newlogins.txt</code>:</p>
<blockquote><p># sh mass_useradd &lt; newusers &gt;&gt; newlogins.txt</p></blockquote>
<p>In addition to the output file, which is a simple list, <code>mass_passwd</code> creates a separate file for each user, containing the new login name and instructions. This makes it easy to print them individually for distribution. These files, plus a log file, are stored in the home directory of the user who runs the scripts (usually root):</p>
<blockquote><p># ls /root/mass_passwds</p>
<p>dawns.passwd.txt  nikitah.passwd.txt  mass_passwd.log  rubst.passwd.txt</p></blockquote>
<p>Because the scripts use standard Shadow Suite utilities, they are easy to customize by adjusting the options for the various utilities used in the scripts.</p>
<p>The output file looks like this:</p>
<blockquote><p>dawns    shabaefi    1002<br />
nikitah  gohbinga    1003<br />
rubst    ahtoohaa    1004</p></blockquote>
<p><code>/etc/passwd</code> looks like this:</p>
<blockquote><p> dawns:x:1002:1002:Dawn Marie Schroder,,123-4567,trainers:/home/dawns:/bin/bash<br />
nikitah:x:1003:1003:Nikita Horse,,123-4567,equine:/home/nikitah:/bin/bash<br />
rubst:x:1004:1004:Rubs The Cat,101,,234-5678,,test:/home/rubst:/bin/bash</p></blockquote>
<p>The individual files generated for each user look like this:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Login name: rubst</p>
<p>Password:   eejahgue</p>
<p>Please log in and change your password; the system should prompt you to do this when you log in.  You can change your password at any time with the &#8216;passwd&#8217; command. Choose a strong password &#8211; everyday words, birthdays, names of people or animals, all these are too eay to guess. Also, DO NOT give your password to anyone, ever.  The IT staff will never ask you for your password, and neither should anyone else.  You will be held responsible for all activity done via your account.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><strong>mass_useradd</strong></p>
<blockquote><p>#!/bin/sh<br />
## Mass Useradd For Linux<br />
## This script extracts new user data from a delimited<br />
## text file, and automatically generates new user accounts.<br />
## It generates a random password for each login, and exports<br />
## the new logins and passwords to a text file.<br />
## Passwords automatically expire at first login. The<br />
## input file format is &#8220;username: full name&#8221; (no quotes) for<br />
## each line.<br />
##<br />
## Mass Useradd creates a &#8220;User Personal Group.&#8221;<br />
## The UID and the GID are the same. User&#8217;s home directories<br />
## are created with restrictive permissions, chmod 700.<br />
## Mass Useradd uses standard Shadow Suite utilities.<br />
## Values and behaviors are easily modifiable, according<br />
## to the individual utility being called.  It calls<br />
## a companion script, mass_passwd, to set each user password.<br />
## You should have received mass_passwd from the same source<br />
## as mass_useradd.<br />
##<br />
## This script was created by Aaron Malone, and modified by<br />
## Meredydd Luff, Peter Samuelson, and Kathryn Hogg.<br />
## Many thanks!<br />
## Carla Schroder wrote the documentation and pestered<br />
## the aforementioned persons to write the script.<br />
## Copyright (C) 2003  Carla Schroder<br />
## carla at bratgrrl dot com<br />
## This program is free software; you can redistribute<br />
## it and/or modify it under the terms of the GNU General<br />
## Public License as published by the Free Software<br />
## Foundation; either version 2 of the License, or (at your<br />
## option) any later version.<br />
##<br />
## This program is distributed in the hope that it will<br />
## be useful, but WITHOUT ANY WARRANTY; without even the<br />
## implied warranty of MERCHANTABILITY or FITNESS FOR A<br />
## PARTICULAR PURPOSE.  See the<br />
## GNU General Public License for more details.<br />
## http://www.fsf.org/licenses/gpl.html<br />
##<br />
##   Usage:<br />
##    #  sh mass_useradd &lt; inputfile &gt;&gt; new-passwords.txt<br />
##</p>
<p>PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:$PATH</p>
<p># Read a line of input.<br />
# the format of the input file must be like this:<br />
# userlogin : FirstName LastName<br />
# to use a comma-delimited file, change IFS=&#8221;:$IFS&#8221; to<br />
# IFS=&#8221;,$IFS&#8221;</p>
<p>while IFS=&#8221;:$IFS&#8221; read username realname; do</p>
<p># First, weed out blank lines and #comments<br />
case &#8220;$username&#8221; in<br />
&#8221; | \#*) continue ;;<br />
esac</p>
<p># this part reads /etc/passwd and /etc/group, and calculates<br />
# the next available UID and GID.<br />
# it starts at {id=1000}, change this to suit<br />
id=$({ getent passwd; getent group; } | cut -f3 -d: | sort -un |<br />
awk &#8216;BEGIN { id=1000 }<br />
$1 =  = id { id++ }<br />
$1 &gt; id { print id; exit }&#8217;)</p>
<p># Now users are added to /etc/group, /etc/passwd,<br />
# and home directories with chmod 700 are created<br />
# Any of the groupadd, useradd, and chmod options<br />
# can be changed to suit<br />
groupadd -g $id $username<br />
useradd -m -c &#8220;$realname&#8221; -g $username -u $id $username<br />
chmod 700 /home/$username</p>
<p># Set the password.  This calls another script from<br />
# this toolkit, mass_passwd, which can be used independently.<br />
# mass_passwd outputs the username, password and userid.<br />
$(dirname $0)/mass_passwd -M $username</p>
<p>done</p></blockquote>
<p><strong>mass_passwd</strong></p>
<blockquote><p>#!/bin/sh<br />
## Mass Password Change for Linux<br />
## This requires the Shadow Suite utilities.<br />
## Usage:<br />
##   mass_passwd username username &#8230;<br />
##   mass_passwd -g groupname groupname &#8230;<br />
##   mass_passwd -a<br />
##<br />
## This program is free software; you can redistribute<br />
## it and/or modify it under the terms of the GNU General<br />
## Public License as published by the Free Software<br />
## Foundation; either version 2 of the License, or (at your<br />
## option) any later version.<br />
##<br />
## This program is distributed in the hope that it will<br />
## be useful, but WITHOUT ANY WARRANTY; without even the<br />
## implied warranty of MERCHANTABILITY or FITNESS FOR A<br />
## PARTICULAR PURPOSE.  See the<br />
## GNU General Public License for more details.<br />
## http://www.fsf.org/licenses/gpl.html</p>
<p>#############################################################</p>
<p>## This is where the &#8220;username.passwd.txt&#8221; files will<br />
## be dumped. It will be created if it doesn&#8217;t already exist<br />
text_file_dir=$HOME/mass_passwds<br />
log_file=mass_passwd.log</p>
<p>## Minimum userid considered a regular (human) user<br />
min_uid=1000</p>
<p>## Length of generated passwords<br />
pass_len=8</p>
<p>## Length of time, in days, before a password expires<br />
pass_expire=90</p>
<p>##############################################################</p>
<p>## Few user-serviceable parts inside.<br />
## You may wish to edit the text between the two &#8212;&#8212;&#8212;<br />
## lines, below.<br />
# Get the name of this program (probably &#8220;mass_passwd&#8221;)<br />
prog=${0##*/}</p>
<p>usage ( ) {<br />
echo &#8220;usage: $prog [-v] [-n] username &#8230;&#8221;<br />
echo &#8221;       $prog [-v] [-n] [-g] groupname &#8230;&#8221;<br />
echo &#8221;       $prog [-v] [-n] [-a]&#8221;<br />
echo &#8221;  -g   change passwords of everyone in a group&#8221;<br />
echo &#8221;  -a   change everyone&#8217;s password&#8221;<br />
echo &#8221;  -v   verbose&#8221;<br />
echo &#8221;  -n   don&#8217;t do it, just simulate (implies -v)&#8221;<br />
exit 0<br />
}</p>
<p>short_usage ( ) {<br />
echo &gt;&amp;2 &#8220;usage: $prog [-v] [-g] [-a] name&#8230;&#8221;<br />
echo &gt;&amp;2 &#8221;       $prog -h    for help&#8221;<br />
exit 1<br />
}</p>
<p># echo something, but only if in verbose mode<br />
vecho ( ) {<br />
test -n &#8220;$verbose&#8221; &amp;&amp; echo &#8220;$@&#8221;<br />
}</p>
<p># Generate a random password.<br />
#<br />
# If pwgen is available, use that &#8211; that&#8217;s what it&#8217;s for, and it works well.<br />
#<br />
# If not, read /dev/urandom and filter out all non-<br />
#alphanumeric characters until we have enough for a password.<br />
# The numbers in the &#8220;tr -d&#8221; are ASCII values, in octal<br />
# notation, of ranges of character values to delete.<br />
#<br />
# Using /dev/urandom like this is very inefficient, but<br />
# who cares?</p>
<p>randompass ( ) {<br />
pwgen $pass_len 1 2&gt;&amp;- ||<br />
tr -d &#8216;[\000-\057][\072-\100][\133-\140][\173-\377]&#8216; &lt; /dev/urandom |<br />
dd bs=$pass_len count=1 2&gt;&amp;-<br />
}</p>
<p># Interpret usernames / groupnames / &#8220;-a&#8221; mode, and return<br />
# a list of usernames<br />
get_users ( ) {<br />
if [ -n "$all_mode" ]; then<br />
getent passwd | awk -F: &#8216;{if ($3 &gt;= &#8216;$min_uid&#8217;) {print $1}}&#8217;<br />
return<br />
fi<br />
if [ -z "$group_mode" ]; then<br />
echo &#8220;$@&#8221;<br />
return<br />
fi</p>
<p># ok, we&#8217;re in group mode, must look up the users who<br />
# belong to a group<br />
while [ -n "$1" ]; do<br />
g_ent=$(getent group &#8220;$1&#8243; 2&gt;&amp;-)<br />
if [ -z "$g_ent" ]; then<br />
echo &gt;&amp;2 &#8220;warning: $1: group not found&#8221;<br />
continue<br />
fi<br />
members=${g_ent##*:}<br />
gid=${g_ent%:*}<br />
gid=${gid##*:}<br />
echo &#8220;$members&#8221; | tr &#8216;,&#8217; &#8216; &#8216;<br />
getent passwd | awk -F: &#8216;{if ($4 =  = &#8216;$gid&#8217;) { print $1 } }&#8217;<br />
shift<br />
done<br />
}</p>
<p>#############################################################</p>
<p>## main body</p>
<p>group_mode=; verbose=; all_mode=; simulate=; eol=;<br />
while [ -z "$eol" ]; do<br />
case &#8220;$1&#8243; in<br />
-g) group_mode=1; shift ;;<br />
-v) verbose=1; shift ;;<br />
-a) all_mode=1; shift ;;<br />
-n) simulate=true; verbose=1; shift ;;<br />
# we&#8217;re called from mass_useradd<br />
-M) mass_out=1; shift ;;<br />
-h | -? | &#8211;help) usage ;;<br />
&#8211;) eol=1; shift ;;<br />
-*) short_usage ;;<br />
*) eol=1 ;;<br />
esac<br />
done</p>
<p># Set up a secure environment and the directory for<br />
# printable text files<br />
PATH=/usr/sbin:/usr/bin:$PATH<br />
umask 077<br />
mkdir -p $text_file_dir<br />
cd $text_file_dir</p>
<p>processed=0<br />
for u in $(get_users &#8220;$@&#8221;); do<br />
vecho -n &#8220;generating password for $u&#8230;&#8221;<br />
pass=$(randompass)<br />
echo &#8220;$u:$pass&#8221; | eval $simulate chpasswd<br />
vecho -n &#8220;.&#8221;<br />
eval $simulate chage -M $pass_expire -d 2003-01-01 $u<br />
vecho -n &#8220;.&#8221;</p>
<p>rm -f $u.passwd.txt<br />
echo &gt; $u.passwd.txt &#8220;\</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Login name: $u</p>
<p>Password:   $pass</p>
<p>Please log in and change your password; the system should prompt you to do this<br />
when you log in.  You can change your password at any time with the &#8216;passwd&#8217; command.<br />
Choose a strong password &#8211; everyday words, birthdays, names of people or animals,<br />
all these are too easy to guess. Use combinations of letters and numbers. Write down your<br />
password in a safe place.<br />
Also, DO NOT give your password to anyone, ever.  The IT<br />
staff will never ask you for your password, and neither<br />
should anyone else.  You will be held responsible for all<br />
activity done via your account.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221;</p>
<p>printf &gt;&gt; $log_file &#8220;$(date)   %-12s %s\\n&#8221; $u $pass<br />
vecho &#8220;$pass&#8221;<br />
if [ -n "$mass_out" ]; then<br />
uid=$(getent passwd $u | cut -f3 -d:)<br />
echo -e &#8220;$u\\t$pass\\t$uid&#8221;<br />
fi<br />
processed=$(expr $processed + 1)<br />
done</p>
<p>if [ $processed -gt 0 ]; then<br />
test -z &#8220;$mass_out&#8221; &amp;&amp;<br />
echo &gt;&amp;2 &#8220;$processed password(s) reset &#8211; see $text_file_dir/$log_file&#8221;<br />
else<br />
echo &gt;&amp;2 &#8220;no users specified &#8211; see &#8216;$prog -h&#8217; for help&#8221;<br />
fi</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/adding-new-users-in-batches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking Password File Integrity</title>
		<link>http://www.xiitec.com/blog/2008/02/01/checking-password-file-integrity/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/checking-password-file-integrity/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 19:47:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[integrity]]></category>
		<category><![CDATA[password file]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=77</guid>
		<description><![CDATA[There&#8217;s a lot going on in all these files (/etc/group, /etc/passwd, /etc/shadow, and /etc/gshadow), and you need some kind of password file syntax integrity checker. You don&#8217;t want to find out that you&#8217;ve made some mistake—like forgetting to give someone a password—after an attacker has broken into your system!
Use pwck for checking /etc/passwd and /etc/shadow, [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot going on in all these files (<code>/etc/group</code>, <code>/etc/passwd</code>, <code>/etc/shadow</code>, and <code>/etc/gshadow</code>), and you need some kind of password file syntax integrity checker. You don&#8217;t want to find out that you&#8217;ve made some mistake—like forgetting to give someone a password—after an attacker has broken into your system!</p>
<p>Use <code>pwck</code> for checking <code>/etc/passwd</code> and <code>/etc/shadow</code>, and use <code>grpck</code> for /etc/group and <code>/etc/gshadow</code>:</p>
<blockquote><p># pwck</p>
<p># grpck</p></blockquote>
<p><code>pwck</code> performs a consistency check on the <code>/etc/passwd</code> and <code>/etc/shadow</code> files. It checks each user account, and verifies that it has:</p>
<ul>
<li>The correct number of fields</li>
<li>A unique user name</li>
<li>A valid user and group identifier</li>
<li>A valid primary group</li>
<li>A valid home directory</li>
<li>A valid login shell</li>
</ul>
<p><code>pwck</code> will report any account that has no password.</p>
<p>When <code>pwck</code> finds an error, your choices are to delete the account or to ignore the account, in which case <code>pwck</code> shuts down and won&#8217;t check any more lines (with one exception: if it finds a duplicate name, it will continue checking even if you don&#8217;t delete the account)</p>
<p><code>grpck</code> checks the <code>/etc/group</code> and <code>/etc/gshadow</code> files to verify that each group has:</p>
<ul>
<li>The correct number of fields</li>
<li>A unique group name</li>
<li>A valid list of members and administrators</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/checking-password-file-integrity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding and Deleting Group Members</title>
		<link>http://www.xiitec.com/blog/2008/02/01/adding-and-deleting-group-members/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/adding-and-deleting-group-members/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 19:41:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[adding]]></category>
		<category><![CDATA[deleting]]></category>
		<category><![CDATA[group members]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=76</guid>
		<description><![CDATA[If you need to give users some group memberships, or delete some users from groups, edit /etc/groups manually. Just copy and paste; it&#8217;s the fastest way.
You may also use adduser and usermod, but beware of sneaky gotchas: adduser will only add a user to one group at a time, but usermod, which allows you to [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to give users some group memberships, or delete some users from groups, edit <code>/etc/groups</code> manually. Just copy and paste; it&#8217;s the fastest way.</p>
<p>You may also use <code>adduser</code> and <code>usermod</code>, but beware of sneaky gotchas: <code>adduser</code> will only add a user to one group at a time, but <code>usermod</code>, which allows you to list several groups at once, will overwrite any existing group assignments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/adding-and-deleting-group-members/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating System Groups with addgroup</title>
		<link>http://www.xiitec.com/blog/2008/02/01/creating-system-groups-with-addgroup/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/creating-system-groups-with-addgroup/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 19:38:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[addgroup]]></category>
		<category><![CDATA[system group]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=75</guid>
		<description><![CDATA[If you need to create some new system groups, and you want to use addgroup, here&#8217;s how to create system groups with addgroup:
# addgroup —system
newsysgroup
You can assign the GID, overriding the default. Remember to stick with your distribution&#8217;s (or your personal) numbering scheme:
# addgroup —system  —gid 300
newsysgroup
]]></description>
			<content:encoded><![CDATA[<p>If you need to create some new system groups, and you want to use <code>addgroup</code>, here&#8217;s how to create system groups with <code>addgroup</code>:</p>
<blockquote><p># addgroup —system<br />
newsysgroup</p></blockquote>
<p>You can assign the GID, overriding the default. Remember to stick with your distribution&#8217;s (or your personal) numbering scheme:</p>
<blockquote><p># addgroup —system  —gid 300<br />
newsysgroup</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/creating-system-groups-with-addgroup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a System User</title>
		<link>http://www.xiitec.com/blog/2008/02/01/creating-a-system-user/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/creating-a-system-user/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 19:36:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[system user]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=74</guid>
		<description><![CDATA[You need to know how to create system users for programs like Postfix, Apache, or Squid. These programs should have their own unique user accounts and not just all pile into &#8220;nobody.&#8221;
Both adduser and useradd can do this. adduser works like this:
# adduser —system  —no-create-home —group squid
Adding system user squid&#8230;
Adding new group squid (109).
Adding [...]]]></description>
			<content:encoded><![CDATA[<p>You need to know how to create system users for programs like Postfix, Apache, or Squid. These programs should have their own unique user accounts and not just all pile into &#8220;nobody.&#8221;</p>
<p>Both <code>adduser</code> and <code>useradd</code> can do this. <code>adduser</code> works like this:</p>
<blockquote><p># adduser —system  —no-create-home —group squid<br />
Adding system user squid&#8230;<br />
Adding new group squid (109).<br />
Adding new user squid (109) with group squid<br />
Not creating home directory</p></blockquote>
<p>Check your work:</p>
<blockquote><p># cat /etc/passwd | grep squid<br />
squid:x:109:109::/home/squid:/bin/false</p></blockquote>
<p>Even though it lists /home/squid, a home directory is not created.</p>
<p>Here&#8217;s how <code>useradd</code> does it:</p>
<blockquote><p># useradd -d /dev/null -g squid -s /bin/false squid</p></blockquote>
<p>The nobody user is the default for a lot of daemons and processes that need a system account, but an increasing number of applications require their own unique users. Use a unique user whenever possible, because it&#8217;s a good security practice. The nobody account is a common cracker target, and you don&#8217;t want to expose all kinds of processes and daemons to a common point of attack.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/creating-a-system-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting Groups with groupdel</title>
		<link>http://www.xiitec.com/blog/2008/02/01/deleting-groups-with-groupdel/</link>
		<comments>http://www.xiitec.com/blog/2008/02/01/deleting-groups-with-groupdel/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 19:31:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Users / Groups]]></category>
		<category><![CDATA[groupdel]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=73</guid>
		<description><![CDATA[If you need to delete a group or groups, and you want to be sure there are no orphaned files or users, first reassign the group members, if necessary, by editing /etc/group. Simply copy and paste them into another group. Then use groupdel to delete the group, and find and chgrp to locate and reassign [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to delete a group or groups, and you want to be sure there are no orphaned files or users, first reassign the group members, if necessary, by editing <code>/etc/group</code>. Simply copy and paste them into another group. Then use <code>groupdel</code> to delete the group, and find and <code>chgrp</code> to locate and reassign the group&#8217;s files to another group.</p>
<p>To delete a group use:</p>
<blockquote><p># groupdel<br />
groupname</p></blockquote>
<p>Deleting a group tends to be messy, because there is no utility for automatically migrating or deleting any files or users belonging to the group. You&#8217;ll need to hunt these down and change the GIDs manually:</p>
<blockquote><p># find / -gid 750<br />
/usr/src/include/lber.h<br />
/usr/src/include/ldap.h<br />
/usr/src/include/ldbm.h</p></blockquote>
<p>You can change these one at a time:</p>
<blockquote><p># chgrp 800 /usr/src/include/lber.h</p></blockquote>
<p>Or you can let find and <code>chgrp</code> do the work:</p>
<blockquote><p> # find / -gid 750 -exec chgrp -v  800 {  } \;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/01/deleting-groups-with-groupdel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

