User management

Examples:

useradd onno

adds new user onno

Note: useradd on my system does not allow you to create usernames with special characters. A simple ”.” is excluded as well:

[root@1038 scripts]# useradd hi_v2.0
useradd: invalid user name 'hi_v2.0'

This is strange, because Webmin, on the same system, does make it possible to create exactly such usernames - as well as usernames which exceed the normal username length restrictions.

If have not been able to figure out yet how Webmin does this.

userdel onno

removes user onno

usermod -e 2009-10-12 onno

sets expiration date for user onno

passwd onno

will prompt you twice for new password for user onno

See also the files:

/etc/passwd

/etc/shadow

Group management

Use groups to display group membership for current user. Do whoami to see who is the current user. Examples:

[onno@1038 root]$ whoami
onno
[onno@1038 root]$ groups
onno
[onno@1038 root]$ exit
exit
[root@1038 root]# whoami
root
[root@1038 root]# groups
root bin daemon sys adm disk wheel 

If you are currently root user, you could also do:

[root@1038 root]# groups onno
onno : onno

To add users to a certain group, do usermod -G (you have to also specify all existing group memberships or they will be revoked):

[root@1038 root]# usermod -G onno,bin onno
[root@1038 root]# groups onno
onno : onno bin

Quota

Here is an excellent tutorial on Linux quota: http://souptonuts.sourceforge.net/quota_tutorial.html.

You need this tutorial, because webmin does cover everything regarding disk quota. For instance, to set the grace period, you need to know about the setquota command.

This command measures disk space in blocks of 512 bytes (no, I don't know why). One megabyte equals 1048576 bytes, so a megabyte expressed in blocks is:

1 Mb = 2048 (blocks)

Now you need to know only one more thing (I'm going to ignore inodes): the grace time is measured in seconds. So, a grace period of 24 hours can expressed as:

24 hours grace = 86400 (seconds)

Using setquota

It's probably easiest to first set the quota for a user, then specify the grace period. Example:

  setquota -u chirico 100 200 10 15  -a /dev/loop0

And then:

  setquota -u chirico -T 86400 /dev/loop0

This sets the block grace period to 24 hours, while we ignore the inode grace period (there is no grace period for inodes). If you want to specify the grace period for a whole partition or disk volume or whatever, do this:

 setquota -t 86400 0 /dev/loop0

Using usermod to Change Passwords

Usermod requires an encrypted password, so you can't use without a little help from crypt. Unfortunately, the crypt library does not come with a client utility (I couldn't find one for my Fedora Core 2 Linux box at least). So, I wrote a little php shell script.

crypt.php

#!/usr/local/bin/php
<?php
  if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
This is a command line PHP script to convert a plain text password into an encrypted string using crypt.
The script uses a random salt string of two characters.

 Usage:
<?php echo $argv[0]; ?> <option>

 <option> Password

<?php
} else {
  $salt = chr(rand(64,126)) . chr(rand(64,126));
  echo crypt($argv[1],$salt);  
}
?>

The location of your php bin, as indicated by the first line, may of course be different on your system.


Personal Tools