How to create user account using Linux useradd command

Manage Linux user account is a very important task in Linux. It begins with creating a user account and creating password for that particular user account and then, you might have to assign group for that user. Maybe at one time you might have to change a user particular (user information) such as update telephone number or department where the user works. You also don't want to keep an account of user who no longer works in your office or temporary officer in your server.

Create user account using Linux useradd command

The Linux useradd command is the traditional command used to create a new user account or modify user's information in Linux system. The useradd command's manual page state very clear about how to do this and it's not very hard to understand. Please read the manual page at least once so that you can see how useradd can assist you doing your administration job. Below is the synopsis from useradd manual page taken from Slackware Linux:

SYNOPSIS
useradd [-c comment] [-d home_dir] [-e expire_date] [-f inactive_time]
[-g initial_group] [-G group[,...]] [-m [-k skeleton_dir]] [-o] [-p passwd]
[-s shell] [-u uid] login

useradd -D [-g default_group] [-b default_home] [-e default_expire_date] [-f default_inactive]
[-s default_shell]

Here is another useradd manual page synopsis taken from Ubuntu Linux:

SYNOPSIS
useradd [options] LOGIN

useradd -D

useradd -D [options]

What you see in other Linux distributions might be different. Other than manual page, you can see synopsis (command's syntax) of useradd command by typing useradd and enter. You should get basic information about useradd command and the right way to issue the command with available options. This is another way of how Linux helps user in command line terminal.

This is an example of how to create a new user using useradd command in Slackware Linux:

[email protected]:~# useradd -g users -d /home/karim -s /bin/bash -c temporary -e 2006-06-30 -m karim
[email protected]:~#

Here are the meaning of command options used in the example above:

  • -g (user initial group) - users
  • -d (user's home directory when login) - /home/karim
  • -s (user's shell) - /bin/bash
  • -c (comment) - Temporary
  • -e (account expired date) - 2009-11-30
  • -m (create user's home directory)
  • karim (username of the new account)

All user's information can be found in /etc/passwd file. We can view the file
with vi /etc/passwd command.

karim:x:1003:100:temporary:/home/karim:/bin/bash

The useradd -D command can be used to modify user account.

Create password for Linux new user account

Now we have to provide a password for the account we've just created. The command to do the job is Linux passwd command. The format for the passwd command is passwd <username>. If you forgot to put the username, linux changes the current user password (user account we are using now), which is the root password.

Let's create password for our new user:

[email protected]:~# passwd karim
Changing password for karim
Enter the new password (minimum of 5, maximum of 127 characters)
Please use a combination of upper and lower case letters and numbers.
New password:
Re-enter new password:
Password changed.

That's it. Now you can switch to other terminal and login with the new user account.

Back to Linux basic commands main page.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.