useradd Linux Commands

What is Linux useradd Command?

Explanation

useradd COMMAND:

useradd - Adds new user to the linux system, with specified user-name. When a new user is added then a corresponding entry is made in files /etc/passwd, /etc/group and /etc/shadow

SYNTAX :


useradd [options] [username]

OPTIONS:


-d Specifies the users home directory
-s Specifies the users shell
-g Specifies the users primary group
-G Specifies the users secondary groups
-M Specifies not to create home directory for the user
-e Specifies the expire date of the user
-uid Specifies the user-id of the user

EXAMPLE:


  1. To add new user:
    useradd hiox

    This command will add a new user with name hiox.
  2. To add user but not allow to login in the system:
    useradd -s /bin/nologin hiox

    This command will add user hiox but not allow to login.
    In above command:
    hiox-Is the user-name
    /bin/nologin-Is Shell assigned to the user
  3. To set expire date of the user:
    useradd -e 2008-06-30 hiox

    This command will add user hiox and set the expire date to 2008-06-30.
    In above command:
    hiox-Is the user-name
    2008-06-30-Is date on which the user-account will be expired
  4. To create user without creating home directory:
    useradd -M hiox

    The above command will create user hiox but home directory will not be created.

Ask Questions

Ask Question