Creating users and groups on a Linux system

During the installation process, most installers will create a standard user account. If a computer needs to be shared by multiple people, then it is desirable to have a separate account for each person who uses it. The useradd command creates a new user account using the default values from the system and the values specified on the command line with the options. The useradd command may also create the new user's home directory and copy initial files. By default, a group will also be created for the new user. The skeleton directory contains files and directories to be copied in the user's home directory, when the home directory is created by useradd, is defined by default in /etc/skel.

$ useradd stan

The -u option allows you to specify the UID. The value must be unique. To specify a group, use the -g option and the group name or number. The group name must exist and a group number must refer to an already existing group. The -G option can be used to specify a list of group names or numbers if you want to make the user a member of one or more groups. The -c option allows to specify the comment field, typically used for the user's full name.

$ useradd -u 1001 -g 1001 -G GROUP1,GROUP2 -c Stan Marsh stan

The groupadd command creates a new group using the default values from the system and the values specified on the command line with the options. The command requires only the name of the group to be created.

$ groupadd example

The -g option can be used to specify a group id for the new group.

$ groupadd -g 506 example

The passwd command changes passwords for user accounts. A normal user may only change password for his/her own account. The user is first prompted for his/her old password. The root user can change password for any account and doesn't have to know old password so that forgotten passwords may be changed. The user is prompted twice for a replacement password. As a general guideline, passwords should consist of 6 to 8 characters including one or more lower case alphabetics, digits 0 thru 9, and punctuation marks.

$ passwd mihael
Changing password for mihael
Current password:
New password:
Retype new password:
passwd: password updated successfully

Once you create a user, the system will generally just increment the UID by one for the next user that you create. The root user has UID of 0. If you are setting up a new system, it is a good practice to start your UIDs no lower than 1000. This also has the advantage of insuring you will have sufficient UIDs available for many system services.