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
In this tutorial:
- Linux Commands
- Command Shell Basics
- Editing commands
- Wildcards
- Redirection and piping
- Environment variables
- Shell scripts
- Directory and File Handling Commands
- The cd command
- The mkdir command
- The rmdir command
- The ls command
- The cp command
- The rm command
- The mv command
- The touch command
- The cat command
- Commands for Working with Packages and Services
- The rpm command
- Commands for Administering Users
- The usermod command
- The chage command
- The passwd command
- The newusers command
- The groupadd command
- The groupdel command
- Commands for Managing Ownership and Permissions
- The chgrp command
- The chmod command
- Networking Commands
- The ipconfig command
- The netstat command
- The ping command
- The route command
- The traceroute command