Linux add a user using command line tools

by Vivek Gite on September 22, 2006 · 10 comments

Q. How do I add a new user using command line tools? What are command line option recommended.

A. You need to use useradd command, which is responsible for creating a new user or update default new user information

The useradd command creates a new user account using the values specified on the command line and the default values from the system. The new user account will be entered into the system files (/etc/passwd) as needed, the home directory (/home/username) will be created, and initial files copied, depending on the command line options.

Task: Add a user to the system

Syntax is as follows for useradd command:
useradd <username>

By default user account is locaked, you need to setup a new password:
passwd <username>

For example add a new user called tom and set password to jerry:
# adduser tom
# passwd tom

If you want to add a user to group read how to add a user user to group

List of common options:

  • -c comment: Add a comment for the user
  • -d home-directory: Create a new home-directory
  • -e yyyy-mm-dd: Date for the account to be disabled
  • -f days: Number of days after the password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.)
  • -g group-name: Primary Group name or group number for the user's default group (group name must exist)
  • -G group-list: List of secondary additional (other than default) group names or group numbers, separated by commas, of which the user is a member (group name must exist)
  • -m: Create the home directory
  • -M: Do not create the home directory
  • -s: User's login shell (default /bin/bash)

To read all command line option type following command:
$ man adduser

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 10 comments… read them below or add one }

1 maruf February 21, 2009

thanks for your information.

Reply

2 digitalpbk May 17, 2009

Thank you
how do you set limits such as disk quota ?

Reply

3 bug March 3, 2010

For example add a new user called tom and set password to jerry:
# adduser tom
# passwd tom

passwd in example should be:
# passwd jerry

Reply

4 BryAnna February 5, 2011

Its actually
useradd or adduser tom
passwd tom
The following prompt will come up after you input “passwd tom” than type jerry
New UNIX password: jerry

Reply

5 newbee April 5, 2010

Use the command called ‘quota’ to set limits for disk usage.

Reply

6 PANYE June 3, 2010

hi please how can i change the acces pasword the ftp server ton enter in my server ebrunie-voip?
i wont to change the access to protect my server agains some fraud.
thank
panye

Reply

7 An M June 26, 2010

i was looking for differences between ‘useradd’ and ‘adduser’, but you seem to mix both….

see this:you first talk about useradd, then you put an example with adduser !

Reply

8 Annie June 24, 2011

How can i manage user from Command Line

Let suppose i create user spiderman and grant Superuser like root!

Reply

9 Mangesh September 19, 2011

Is it possible to create user and password in single cmd?

useradd -m user1 -p passwordforuser1

Reply

10 G8KeaPoR December 22, 2011

Be sure to man useradd as there are a bunch of other options that this article leaves out like adding keys, names, passwords, and other things. man is your friend learn to use it or you will hate life in linux/unix

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 3 + 12 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: