Wednesday 31/12/2008
This document describes basic user management in Fedora Core linux. User management for a local non-directory/nis configuration is controlled through the 3 files /etc/passwd, /etc/shadow and /etc/group and basic database (table file) management is discussed
Note: Be sure to assign a unique id for the new user
A new user can be created quite simply by adding a new entry to the /etc/passwd and /etc/group files. A common configuration for local user management (i.e., non-directory managed users) is to create a user and group of the same name and also create a home directory for that user. It is important to remember to use a unique id(1) for the new user. The relevant files for locally managed users are:
/etc/passwd /etc/shadow /etc/group
In the following example, a new user called foo is created with a uid of 500 and is assigned to group foo (which has gid 200). A home directory is created of the same name and is chown(1)'d to the new user and the new users' passwd is reset to foo. For illustrative purposes, the new user is simple shown after an editing session (e.g., :vim or similar) using cat(1) and grep(1). The results of the grep can be pasted into the releveant files.
bash $ cat /etc/passwd | grep foo foo:x:500:200:Foo User:/home/foo:/bin/bash
bash $ cat /etc/group | grep foo foo:x:200:
bash $ cat /etc/shadow | grep foo foo:NP:14243:0:99999:7:::
bash # mkdir -p /home/foo bash # chown -R foo:foo /home/foo bash # passwd foo
The commandline app useradd(8) (also adduser(8)) or the gui app system-config-users(8) can also be used (perhaps in preference to) editing the user database tables (files) /etc/passwd and related
The preferred means of creating (and certainly of modifying an existing) user is to use useradd(8). The useradd program has a number of options which allow the system admin to control user properties such as shell, groups, home directory, home directory creation and so on. The following example creates a new user called foo, and configures the new user to belong to primary group foo and be located in /home/foo.
Note: Primary group must already exist, see groupadd(8)
bash # useradd -d /home/foo -g foo foo
If no options are given to useradd, then the configured defaults are used. For example, the following creates user bar with basic defaults configured. This command also creates the user's home directory.
bash # useradd bar
Be sure to use usermod(1M) to change the uid of an existing user as this will update most of the references to the old uid. However, some programs (:gnome, :pulseaudio and similar) will create files and sockets and these may need to be chown(1)'d to the new userid. This is most especially true of :gnome and gconfd which attempt to reuse sockets and pipes based on a particular patten. These must be accessble and writable by the user on login otherwise :gnome may fail to start (properly). In the following output we see that gconfd and :gnome (along with esd and :pulseaudo) have created several files in the /tmp directory owned by the current user.
drwxrwxrwt 29 root root 4096 2008-12-31 16:15 ./ drwxr-xr-x 21 root root 4096 2008-12-29 13:22 ../ drwx------ 2 foo foo 4096 2008-12-31 16:12 .esd-1001/ drwx------ 3 foo foo 4096 2008-12-31 16:12 gconfd-foo/ drwx------ 2 gdm gdm 4096 2008-12-31 16:12 gconfd-gdm/ srwxr-xr-x 1 foo foo 0 2008-12-30 14:31 gnome-system-monitor.foo.555129140= drwx------ 2 foo foo 4096 2008-12-31 16:12 orbit-foo/ drwx------ 2 gdm gdm 4096 2008-12-31 16:12 orbit-gdm/ drwx------ 2 foo foo 4096 2008-12-31 16:12 pulse-foo/ drwx------ 2 foo foo 4096 2008-12-24 10:12 virtual-foo.gIiNhm/
Warning: Change ownership of files and directories owned by the old uid
Be sure to chown(1) any directories marked as owned by the old userid, swapping their owner ship to the new uid of the user in question. This will avoid potential window manager issues (especially with :gnome) and resource conflicts (especially :pulseaudio and esd)
bash # usermod --uid 1000 foo
wp?imperfect_competition dieman?ls(1) :Home
Stuart Moorfoot © 31 Dec 2008 foo@bund.com.au