cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:command:useradd.html



Linux Commands Cheat Sheet

How to use useradd commad in Linux

HELP/Manual

# useradd -h

Options:
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -m, --create-home             create the user's home directory
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
# man useradd
      -m, --create-home
          The user's home directory will be created if it does not exist.

       -r This flag is used to create a system account. That is, a user with a UID lower than the value of
          UID_MIN defined in /etc/login.defs and whose password does not expire. Note that useradd will not
          create a home directory for such an user, regardless of the default setting in /etc/login.defs. 
          You have to specify -m option if you want a home directory for a system account to be created.
          This is an option added by Red Hat

       -s, --shell SHELL
           The name of a new user's login shell.

       -g, --gid GROUP
           The group name or number of the user's initial login group.

       -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
           A list of supplementary groups which the user is also a member of.

       -u, --uid UID
           The numerical value of the user's ID. This value must be unique

Example

useradd -u UID -g GROUP -G GROUP1,GROUP2 -s /bin/bash -d HOME_DIR   USER1

# Adminuser on RHEL
useradd -G wheel USER1
useradd -u 1001 -g admin -G wheel -m  USER1

# Adminuser on Ubuntu
useradd -m -s /bin/bash -G sudo  USER2

How to create system user

useradd -r apache
useradd -r nginx



os/linux/command/useradd.html.txt ยท Last modified: 2021/02/23 by admin

Page Tools