Solaris Tips

User creation - the neat way

Solaris comes with automount enabled by default. Also, it transparently allows mounting a directory in an already mounted filesystem elsewhere without using NFS. The idea is to have the user home directories "physically" in /export/home and to mount them under /home on an as needed basis.

If you create the users through the Solaris Management Console or through admintool, it will automatically set up this scheme, but the command line tools force you to do it manually.

The procedure

  1. First, you create the new user with useradd, using /export/home/<username> as home directory:
    # useradd -d /export/home/sample -c "Sample user" sample
    
    You can optionally use the -m switch to make useradd copy the files in /etc/skel to the new directory.
  2. Now you have to modify the file /etc/auto_home and add a line for the new user:
    sample hostname:/export/home/sample
    
    (replacing hostname with the machine hostname, of course)
  3. Then, modify the user to use this new home:
    # usermod -d /home/sample sample
    

Note that, from now on, opening the /home/sample directory (by logging in as sample, cd'ing, etc) will trigger the mounting of /export/home/sample there. Ten minutes (configurable) after the directory being closed, it will be umounted. df -k whill show something like this:

Filesystem            kbytes    used   avail capacity  Mounted on
...
/export/home/sample
                     1621767 1511297   61817    97%    /home/sample

People who come from *BSD will find /usr/ucb/vipw handy for these kind of tasks.