• 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 not found

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

If you encounter the below error while running the useradd command:

useradd: command not found

you may try installing the below package as per your choice of distribution.

Distribution Command
Debian apt-get install passwd
Ubuntu apt-get install passwd
Alpine apk add shadow
Arch Linux pacman -S shadow
Kali Linux apt-get install passwd
Fedora dnf install shadow-utils-2
Raspbian apt-get install passwd

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 a user with mentioning home directory:

# useradd -d /tmp/geek geek 

4. To add a user with an expiration date:

# useradd -e 2013-12-31 geek 

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

# useradd -f 2 geek 

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

# useradd -g UNIX geek 

7. To add a user by mentioning secondary groups to it:

# useradd -G Support,IT geek

8. To add a user while not creating the home directory for it:

# useradd -M geek

9. To create a user with a duplicate UID:

# useradd -u 500 -o geek 

10. To create a system account:

# useradd -r geek 

11. Creating a user by assigning a specific shell to him:

# useradd -s /bin/bash geek 

12. Creating a user with a particular user ID:

# useradd -u 521 geek 

Conclusion

The useradd command, when run without options, creates a user account with default parameters. The default parameters are read from the /etc/login.defs file and include parameters such as valid UID, GID number, default password aging rules, etc. Values from this file are used while creating a new user only. Apart from useradd, we can also use the adduser command to create a local user account in Linux. You can read more about adduser in the man page, using the man adduser command.

Filed Under: Linux

Some more articles you might also be interested in …

  1. cradle: The Cradle PHP framework (Command Examples)
  2. Understanding the /proc/mounts, /etc/mtab and /proc/partitions files
  3. add-apt-repository Command Examples
  4. Magento 2.3.3 Redis cache grows unlimited
  5. upower: command not found
  6. grub2-mkpasswd-pbkdf2: command not found
  7. CentOS / RHEL 7 : How to disable Transparent Huge pages (THP)
  8. sacctmgr: command not found
  9. cpufreq-info Command Examples in Linux
  10. httpd Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • csslint: A linter for CSS code
  • csh: The shell (command interpreter) with C-like syntax (Command Examples)
  • csc: The Microsoft C# Compiler (Command Examples)
  • crystal: Tool for managing Crystal source code

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright