[Fix] Linux - bash: useradd: command not found

# useradd dev1
bash: useradd: command not found

# which useradd
which: no useradd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)

The most common reason for not being able to execute the useradd command on Linux is that you do not have the required packages installed.

Fix: useradd command not found

Install the shadow-utils using the yum package manager,

# yum install shadow-utils


Dependencies Resolved

 Package Arch Version Repository Size
 shadow-utils             aarch64             2:              amzn2-core             1.1 M
Installing for dependencies:
 audit-libs               aarch64             2.8.1-3.amzn2.1                     amzn2-core              99 k
 libcap-ng                aarch64             0.7.5-4.amzn2.0.4                   amzn2-core              25 k
 libsemanage              aarch64             2.5-11.amzn2                        amzn2-core             150 k
 ustr                     aarch64             1.0.4-16.amzn2.0.3                  amzn2-core              90 k

Transaction Summary
Install  1 Package (+4 Dependent packages)

Total download size: 1.4 M
Installed size: 4.8 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): audit-libs-2.8.1-3.amzn2.1.aarch64.rpm                                                                      |  99 kB  00:00:00     
(2/5): libsemanage-2.5-11.amzn2.aarch64.rpm                                                                        | 150 kB  00:00:00     
(3/5): libcap-ng-0.7.5-4.amzn2.0.4.aarch64.rpm                                                                     |  25 kB  00:00:01     
(4/5): ustr-1.0.4-16.amzn2.0.3.aarch64.rpm                                                                         |  90 kB  00:00:01     
(5/5): shadow-utils-                                                               | 1.1 MB  00:00:03     
Total                                                                                                     223 kB/s | 1.4 MB  00:00:06     
Running transaction check

  shadow-utils.aarch64 2:                                                                                             

Dependency Installed:
  audit-libs.aarch64 0:2.8.1-3.amzn2.1          libcap-ng.aarch64 0:0.7.5-4.amzn2.0.4          libsemanage.aarch64 0:2.5-11.amzn2         
  ustr.aarch64 0:1.0.4-16.amzn2.0.3            

# useradd dev1

# cat /etc/passwd | grep dev 
Fix useradd command Linux

Tested on Amazon Linux Docker Image

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap