• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

useradd Command Examples in Linux

by admin

The useradd command is used to create user accounts and configure basic settings. As part of the account creation process, useradd references several files:

  • The account is stored in the /etc/passwd file.
  • The account is configured according to various options set in the /etc/login.defs file.
  • The account’s home directory is created at the /home/[account name] directory.
  • The account’s home directory is populated using files from the /etc/skel directory.

By default, the useradd command does not set a password for the account. Since most Linux distributions will not permit a blank password, the account will exist but is not yet usable.

Syntax of useradd command

The syntax of the useradd command is:

# useradd [options] [user name]

useradd Command options

The useradd command includes many options to customize user accounts, as detailed in the below table.

Option Description Example
-c Sets Comment Field # useradd -c “User one” user01
-e Sets account expiration date # useradd -e 2021/12/31
-s Sets user’s default shell # useradd -s /bin/bash
-D view default config for new users # useradd -D

useradd Command Examples

1. Adding the user with the default settings:

# useradd geek 

2. To add the user with mentioning comments:

# useradd -c "Anything" geek 

3. To add user with mentioning home directory:

# useradd -d /tmp/geek geek 

4. To add user with expiration date:

# useradd -e 2013-12-31 geek 

5. To add user account with number of days of inactivity:

# useradd -f 2 geek 

6. To add user with specifying primary group to it:

# useradd -g UNIX geek 

7. To add user with mentioning secondary groups to it:

# useradd -G Support,IT geek

8. To add user while home directory will not be created for it:

# useradd -M geek

9. To create a user with duplicate UID:

# useradd -u 500 -o geek 

10. To create a system account:

# useradd -r geek 

11. Creating user with assigning specific shell to him:

# useradd -s /bin/bash geek 

12. Creating user with particular user ID:

# useradd -u 521 geek 

Filed Under: Linux

Some more articles you might also be interested in …

  1. mpstat Command Examples in Linux
  2. CentOS / RHEL 7 : How to boot into rescue mode from installation DVD/ISO
  3. file: command not found
  4. iw: command not found
  5. CentOS / RHEL 4 : How to install and configure FTP server (vsftpd)
  6. Basic Master Cups Server and Clients Configuration for Browsing in CentOS/RHEL 7
  7. Volume “test_vg/lvol0” is not active locally – Error while running lvcreate
  8. ports Command Examples in Linux
  9. CentOS / RHEL 6 : How to disable IPv6
  10. createrepo: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • cf: Command-line tool to manage apps and services on Cloud Foundry
  • certutil: Manage keys and certificates in both NSS databases and other NSS tokens
  • cdk: A CLI for AWS Cloud Development Kit (CDK)
  • cd: Change the current working directory

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright