Networking / Beginners

Commands for Administering Users

The following sections describe the Linux commands that you can use to create and manage user accounts from a command shell.

Tip You should log on as root to perform these tasks.

The useradd command

The useradd command creates a user account. Here's the basic syntax for adding a new user:

useradd [options] user-name

You can also use this command to change the default options for new users. In that case, the syntax is more like this:

useradd -D [options]

The options are as follows:

  • -c comment: Typically, the comment is the user's full name.
  • -d home-dir: The home directory of the new user.
  • -e date: The expiration date for the user.
  • -f time: The number of days between logons before the user is considered expired.
  • -g group: The initial logon group for the user.
  • -G groups: Additional groups the user should belong to.
  • -m: Creates the new user's home directory if it doesn't exist already.
  • -s shell-path: Specifies the user's logon shell.

The following option is valid only with -D:

  • -b base-dir: Provides the default base directory if a home directory is not specified.

Its most basic form, the useradd command, creates a user with default option settings:

$ useradd theodore

This command creates a user named theodore.
Here's a command that specifies the user's full name in the comment option:

$ useradd -c 'Theodore Cleaver' theodore

The following command creates a temporary account named ghost that expires on Halloween 2012:

$ useradd -e 2012-10-31 ghost

If you want to see what the default values are for account options, use the -D option without any other parameters:

$ useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
[Previous] [Contents] [Next]