How to Fix “semanage command” Not Found Error in CentOS

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

I am trying to configure a pgadmin4 with correct and default security context values using a setup-web.sh script. it has semanage command to make changes in SELinux policy to allow access to pgAdmin but I suddenly encountered the following error.

[root@unixcop ~]# /usr/pgadmin4/bin/setup-web.sh
Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
pgAdmin 4 - Application Initialisation
======================================

Creating storage and log directories...
Configuring SELinux...
/usr/pgadmin4/bin/setup-web.sh: line 87: semanage: command not found
/usr/pgadmin4/bin/setup-web.sh: line 89: semanage: command not found
The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? y
Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4

The error was that semanage command not found.

semanage

The semanage command is an SELinux (SecurityEnhanced Linux) management tool that’s used to configure specific elements without making any adjustments to or reassembling from policy sources. Semanage consist of mapping from Linux username to SELinux user identities and it also includes mapping security context for numerous kind of objects like interface, network port, etc.

You need to use yum provides, this option to find out the package that provides the queried file called /usr/sbin/semanage.

We will explain how to install necessary packages for getting semanage command using the yum command.

[root@unixcop ~]# yum provides /usr/sbin/semanage
Last metadata expiration check: 0:20:11 ago on Mon Aug  9 10:46:23 2021.
policycoreutils-python-utils-2.9-14.el8.noarch : SELinux policy core python utilities
Repo        : baseos
Matched from:
Filename    : /usr/sbin/semanage

You can see that we need to install policycoreutils-python-utils-2.9-14.el8.noarch package to use the semanage command.

[root@unixcop ~]# yum install policycoreutils-python-utils

Last metadata expiration check: 0:20:24 ago on Mon Aug  9 10:46:23 2021.
Dependencies resolved.
======================================================================================================================================================
 Package                                       Architecture            Version                                          Repository               Size
======================================================================================================================================================
Installing:
 policycoreutils-python-utils                  noarch                  2.9-14.el8                                       baseos                  252 k
Installing dependencies:
 checkpolicy                                   x86_64                  2.9-1.el8                                        baseos                  348 k
 python3-audit                                 x86_64                  3.0-0.17.20191104git1c2f876.el8                  baseos                   86 k
 python3-libsemanage                           x86_64                  2.9-6.el8                                        baseos                  127 k
 python3-policycoreutils                       noarch                  2.9-14.el8                                       baseos                  2.2 M
 python3-setools                               x86_64                  4.3.0-2.el8                                      baseos                  626 k

Transaction Summary
======================================================================================================================================================
Install  6 Packages

Total download size: 3.6 M
Installed size: 11 M
Is this ok [y/N]: Operation aborted.
[root@unixcop ~]# yum install policycoreutils-python-utils
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:20:29 ago on Mon Aug  9 10:46:23 2021.
Dependencies resolved.
======================================================================================================================================================
 Package                                       Architecture            Version                                          Repository               Size
======================================================================================================================================================
Installing:
 policycoreutils-python-utils                  noarch                  2.9-14.el8                                       baseos                  252 k
Installing dependencies:
 checkpolicy                                   x86_64                  2.9-1.el8                                        baseos                  348 k
 python3-audit                                 x86_64                  3.0-0.17.20191104git1c2f876.el8                  baseos                   86 k
 python3-libsemanage                           x86_64                  2.9-6.el8                                        baseos                  127 k
 python3-policycoreutils                       noarch                  2.9-14.el8                                       baseos                  2.2 M
 python3-setools                               x86_64                  4.3.0-2.el8                                      baseos                  626 k

Transaction Summary
======================================================================================================================================================
Install  6 Packages

Total download size: 3.6 M
Installed size: 11 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm                                                        66 kB/s |  86 kB     00:01    
(2/6): python3-libsemanage-2.9-6.el8.x86_64.rpm                                                                       113 kB/s | 127 kB     00:01    
(3/6): policycoreutils-python-utils-2.9-14.el8.noarch.rpm                                                              98 kB/s | 252 kB     00:02    
(4/6): checkpolicy-2.9-1.el8.x86_64.rpm                                                                                94 kB/s | 348 kB     00:03    
(5/6): python3-setools-4.3.0-2.el8.x86_64.rpm                                                                         172 kB/s | 626 kB     00:03    
(6/6): python3-policycoreutils-2.9-14.el8.noarch.rpm                                                                  223 kB/s | 2.2 MB     00:10    
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                 279 kB/s | 3.6 MB     00:13     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                              1/1 
  Installing       : python3-setools-4.3.0-2.el8.x86_64                                                                                           1/6 
  Installing       : python3-libsemanage-2.9-6.el8.x86_64                                                                                         2/6 
  Installing       : python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                                                         3/6 
  Installing       : checkpolicy-2.9-1.el8.x86_64                                                                                                 4/6 
  Installing       : python3-policycoreutils-2.9-14.el8.noarch                                                                                    5/6 
  Installing       : policycoreutils-python-utils-2.9-14.el8.noarch                                                                               6/6 
  Running scriptlet: policycoreutils-python-utils-2.9-14.el8.noarch                                                                               6/6 
  Verifying        : checkpolicy-2.9-1.el8.x86_64                                                                                                 1/6 
  Verifying        : policycoreutils-python-utils-2.9-14.el8.noarch                                                                               2/6 
  Verifying        : python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                                                         3/6 
  Verifying        : python3-libsemanage-2.9-6.el8.x86_64                                                                                         4/6 
  Verifying        : python3-policycoreutils-2.9-14.el8.noarch                                                                                    5/6 
  Verifying        : python3-setools-4.3.0-2.el8.x86_64                                                                                           6/6 

Installed:
  checkpolicy-2.9-1.el8.x86_64             policycoreutils-python-utils-2.9-14.el8.noarch     python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64    
  python3-libsemanage-2.9-6.el8.x86_64     python3-policycoreutils-2.9-14.el8.noarch          python3-setools-4.3.0-2.el8.x86_64                      

Complete!

Try running the semanage command again, it will work like magic.

You can also use the following commands to get the manual page on semanage command options and usage.

# man semanage
# semanage --help

Also i can check that with running my setup-web.sh script again.

[root@unixcop ~]# /usr/pgadmin4/bin/setup-web.sh
Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
pgAdmin 4 - Application Initialisation
======================================

Creating storage and log directories...
Configuring SELinux...
The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? y
Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4

It was-run correctly.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook