[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
======================================
Installing:
 shadow-utils             aarch64             2:4.1.5.1-24.amzn2.0.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-4.1.5.1-24.amzn2.0.2.aarch64.rpm                                                               | 1.1 MB  00:00:03     
------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                     223 kB/s | 1.4 MB  00:00:06     
Running transaction check
..

Installed:
  shadow-utils.aarch64 2:4.1.5.1-24.amzn2.0.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            

Complete!
# useradd dev1

# cat /etc/passwd | grep dev 
dev1:x:1000:1000::/home/dev1:/bin/bash
Fix useradd command Linux

Tested on Amazon Linux Docker Image

-


Have Questions? Post them here!

Topics Coverage:


🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram