Thursday, January 17, 2008

Creating a new user

There are several tasks involved in setting up a new user. The login name must be added to the system, the user must be assigned to a group, a home directory must be created for him, and a profile set up in his home directory. Only user root can create new users.
Different types of Unix and Linux installations have different methods of managing user accounts. Most installations have a GUI tool for this purpose. The GUI tool will generally create the user and his home directory, as well as assigning him to a group and giving him a password. The .profile in his home directory must be set up with a text editor, or copied from another user with similar settings.
If you prefer working from the command line, most installations support the useradd command. If you are using this command, you must either first create the user’s home directory, or use the appropriate switch to create it with useradd. The login name of the new user is given as an argument to the command. The useradd command has the following switches:
-d Specify home directory name
-g Specify either a group name or Group ID
-c Specify a comment
-f Specify the number of inactive days before the account is disabled
-e Expiry date in the form YYYY-MM-DD
-m Create home directory
-k Create skeleton entries in home directory
-G Specify list of supplementary groups
-s Specify the shell
-u Specify the UID
You must then make the new user the owner of his home directory, and, optionally, create a .profile script in this directory. Finally, the new user must be given a password.
To create a user with login name sam belonging to group student with a home directory named /usr/sam, the commands are:
mkdir /usr/sam
useradd –g student –d /usr/sam sam
chown sam /usr/sam
passwd sam
You will then be prompted for sam’s password, and asked to verify it.

No comments: