A while ago, I was trying to configure Apache server to listen to a different port other than its default port i.e 80. After I made the necessary changes in the Apache configuration file and allowed the custom port via firewall, the apache server still refused to listen on the custom port. After a bit of googling, I figured out that SELinux doesn't allow the port, so I ran the following command to make the Apache server to listen on the different port:
# semanage port -a -t ftp_port_t -p tcp 8090
Here, 8090 is port that I want Apache server to listen.
But it threw another error:
-bash: semanage: command not found
I have no idea which package would provides the 'semanage' command on my CentOS system. If you ever wondered how to fix this error in RHEL 7&8 and CentOS 7&8 versions, find which provides the semanage command and install it as described below.
Table of Contents
semanage command not found in CentOS 7/8 And RHEL 7/8
First we will see how to fix this in CentOS 8 server.
Fix "semanage command not found" error in CentOS 8 & RHEL 8
First let us find out which package provides the "semanage" command. To do so, run the following command:
# dnf provides /usr/sbin/semanage
Or,
# dnf whatprovides /usr/sbin/semanage
Sample output from CentOS 8 server:
Last metadata expiration check: 0:32:47 ago on Saturday 08 February 2020 12:02:37 PM IST. policycoreutils-python-utils-2.9-3.el8.noarch : SELinux policy core python utilities Repo : BaseOS Matched from: Filename : /usr/sbin/semanage policycoreutils-python-utils-2.9-3.el8_1.1.noarch : SELinux policy core python utilities Repo : BaseOS Matched from: Filename : /usr/sbin/semanage
As you can see, the package named "policycoreutils-python-utils-2.9-3.el8_1.1.noarch" provides the "semanage" command and it is available in the default repository i.e. BaseOS.
So, let us install this package using the following command as root user:
# dnf install policycoreutils-python-utils
Sample output:
CentOS-8 - AppStream 2.9 kB/s | 4.3 kB 00:01
CentOS-8 - Base 4.5 kB/s | 3.8 kB 00:00
CentOS-8 - Extras 1.7 kB/s | 1.5 kB 00:00
Dependencies resolved.
==========================================================================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================================================================
Installing:
policycoreutils-python-utils noarch 2.9-3.el8_1.1 BaseOS 250 k
Installing dependencies:
checkpolicy x86_64 2.9-1.el8 BaseOS 348 k
python3-audit x86_64 3.0-0.10.20180831git0047a6c.el8 BaseOS 85 k
python3-libsemanage x86_64 2.9-1.el8 BaseOS 127 k
python3-policycoreutils noarch 2.9-3.el8_1.1 BaseOS 2.2 M
python3-setools x86_64 4.2.2-1.el8 BaseOS 600 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.10.20180831git0047a6c.el8.x86_64.rpm 215 kB/s | 85 kB 00:00
(2/6): python3-libsemanage-2.9-1.el8.x86_64.rpm 304 kB/s | 127 kB 00:00
(3/6): policycoreutils-python-utils-2.9-3.el8_1.1.noarch.rpm 258 kB/s | 250 kB 00:00
(4/6): checkpolicy-2.9-1.el8.x86_64.rpm 260 kB/s | 348 kB 00:01
(5/6): python3-setools-4.2.2-1.el8.x86_64.rpm 296 kB/s | 600 kB 00:02
(6/6): python3-policycoreutils-2.9-3.el8_1.1.noarch.rpm 490 kB/s | 2.2 MB 00:04
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 594 kB/s | 3.6 MB 00:06
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : python3-setools-4.2.2-1.el8.x86_64 1/6
Installing : python3-libsemanage-2.9-1.el8.x86_64 2/6
Installing : python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64 3/6
Installing : checkpolicy-2.9-1.el8.x86_64 4/6
Installing : python3-policycoreutils-2.9-3.el8_1.1.noarch 5/6
Installing : policycoreutils-python-utils-2.9-3.el8_1.1.noarch 6/6
Running scriptlet: policycoreutils-python-utils-2.9-3.el8_1.1.noarch 6/6
Verifying : checkpolicy-2.9-1.el8.x86_64 1/6
Verifying : policycoreutils-python-utils-2.9-3.el8_1.1.noarch 2/6
Verifying : python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64 3/6
Verifying : python3-libsemanage-2.9-1.el8.x86_64 4/6
Verifying : python3-policycoreutils-2.9-3.el8_1.1.noarch 5/6
Verifying : python3-setools-4.2.2-1.el8.x86_64 6/6
Installed:
policycoreutils-python-utils-2.9-3.el8_1.1.noarch checkpolicy-2.9-1.el8.x86_64 python3-audit-3.0-0.10.20180831git0047a6c.el8.x86_64
python3-libsemanage-2.9-1.el8.x86_64 python3-policycoreutils-2.9-3.el8_1.1.noarch python3-setools-4.2.2-1.el8.x86_64
Complete!
That's it. Now we can manage SELinux polcies using semanage command.
Note:
If you don't know the exact path of semange command, you can simply run the following command:
# dnf provides semanage
Or,
# dnf provides */semanage
Or,
# dnf whatprovides */semanage
This will display the same result as above commands.
Usually the executable files are located in any one of these locations - /usr/sbin and /usr/bin and /usr/local/bin. Hence, we can search directly in these locations.
To get help, run:
# semanage -h
Sample output:
usage: semanage [-h] {import,export,login,user,port,ibpkey,ibendport,interface,module,node,fcontext,boolean,permissive,dontaudit} ... semanage is used to configure certain elements of SELinux policy with-out requiring modification to or recompilation from policy source. positional arguments: {import,export,login,user,port,ibpkey,ibendport,interface,module,node,fcontext,boolean,permissive,dontaudit} import Import local customizations export Output local customizations login Manage login mappings between linux users and SELinux confined users user Manage SELinux confined users (Roles and levels for an SELinux user) port Manage network port type definitions ibpkey Manage infiniband ibpkey type definitions ibendport Manage infiniband end port type definitions interface Manage network interface type definitions module Manage SELinux policy modules node Manage network node type definitions fcontext Manage file context mapping definitions boolean Manage booleans to selectively enable functionality permissive Manage process type enforcement mode dontaudit Disable/Enable dontaudit rules in policy optional arguments: -h, --help show this help message and exit
Also, refer man pages.
# man semanage
Fix "semanage command not found" error in CentOS 7 & RHEL 7
To figure out which package will provide semanage command on CentOS 7, run:
# yum provides /usr/sbin/semanage
Or,
# yum whatprovides /usr/sbin/semanage
Sample output from my CentOS 7 server:
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.nbrc.ac.in
* extras: mirror.nbrc.ac.in
* updates: mirror.nbrc.ac.in
policycoreutils-python-2.2.5-11.el7.x86_64 : SELinux policy core python
: utilities
Repo : base
Matched from:
Filename : /usr/sbin/semanage
policycoreutils-python-2.2.5-11.el7_0.1.x86_64 : SELinux policy core python
: utilities
Repo : updates
Matched from:
Filename : /usr/sbin/semanage
As you see in the above output, we need to install the package policycoreutils-python-2.2.5-11.el7_0.1.x86_64 in order to use 'semanage' command.
So, let us install policycoreutils-python-2.2.5-11.el7_0.1.x86_64 package using the following command as root user:
# yum install policycoreutils-python
Sample output:
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
policycoreutils-python x86_64 2.2.5-20.el7 base 435 k
Installing for dependencies:
audit-libs-python x86_64 2.4.1-5.el7 base 69 k
checkpolicy x86_64 2.1.12-6.el7 base 247 k
libcgroup x86_64 0.41-8.el7 base 64 k
libsemanage-python x86_64 2.1.10-18.el7 base 94 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.7-46.el7 base 485 k
Updating for dependencies:
audit x86_64 2.4.1-5.el7 base 234 k
audit-libs x86_64 2.4.1-5.el7 base 80 k
libsemanage x86_64 2.1.10-18.el7 base 123 k
policycoreutils x86_64 2.2.5-20.el7 base 803 k
Transaction Summary
================================================================================
Install 1 Package (+6 Dependent packages)
Upgrade ( 4 Dependent packages)
Total download size: 2.6 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/11): audit-libs-2.4.1-5.el7.x86_64.rpm | 80 kB 00:02
(2/11): audit-libs-python-2.4.1-5.el7.x86_64.rpm | 69 kB 00:02
(3/11): checkpolicy-2.1.12-6.el7.x86_64.rpm | 247 kB 00:02
(4/11): libsemanage-2.1.10-18.el7.x86_64.rpm | 123 kB 00:01
(5/11): audit-2.4.1-5.el7.x86_64.rpm | 234 kB 00:04
(6/11): libsemanage-python-2.1.10-18.el7.x86_64.rpm | 94 kB 00:02
(7/11): policycoreutils-python-2.2.5-20.el7.x86_64.rpm | 435 kB 00:03
(8/11): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:02
(9/11): setools-libs-3.3.7-46.el7.x86_64.rpm | 485 kB 00:08
(10/11): policycoreutils-2.2.5-20.el7.x86_64.rpm | 803 kB 00:10
(11/11): libcgroup-0.41-8.el7.x86_64.rpm | 64 kB 00:37
--------------------------------------------------------------------------------
Total 71 kB/s | 2.6 MB 00:37
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : audit-libs-2.4.1-5.el7.x86_64 1/15
Updating : libsemanage-2.1.10-18.el7.x86_64 2/15
Updating : policycoreutils-2.2.5-20.el7.x86_64 3/15
Installing : libsemanage-python-2.1.10-18.el7.x86_64 4/15
Installing : audit-libs-python-2.4.1-5.el7.x86_64 5/15
Installing : python-IPy-0.75-6.el7.noarch 6/15
Installing : checkpolicy-2.1.12-6.el7.x86_64 7/15
Installing : libcgroup-0.41-8.el7.x86_64 8/15
Installing : setools-libs-3.3.7-46.el7.x86_64 9/15
Installing : policycoreutils-python-2.2.5-20.el7.x86_64 10/15
Updating : audit-2.4.1-5.el7.x86_64 11/15
Cleanup : policycoreutils-2.2.5-11.el7_0.1.x86_64 12/15
Cleanup : libsemanage-2.1.10-16.el7.x86_64 13/15
Cleanup : audit-2.3.3-4.el7.x86_64 14/15
Cleanup : audit-libs-2.3.3-4.el7.x86_64 15/15
Verifying : setools-libs-3.3.7-46.el7.x86_64 1/15
Verifying : libsemanage-2.1.10-18.el7.x86_64 2/15
Verifying : libcgroup-0.41-8.el7.x86_64 3/15
Verifying : checkpolicy-2.1.12-6.el7.x86_64 4/15
Verifying : policycoreutils-2.2.5-20.el7.x86_64 5/15
Verifying : python-IPy-0.75-6.el7.noarch 6/15
Verifying : audit-libs-2.4.1-5.el7.x86_64 7/15
Verifying : libsemanage-python-2.1.10-18.el7.x86_64 8/15
Verifying : audit-2.4.1-5.el7.x86_64 9/15
Verifying : policycoreutils-python-2.2.5-20.el7.x86_64 10/15
Verifying : audit-libs-python-2.4.1-5.el7.x86_64 11/15
Verifying : audit-libs-2.3.3-4.el7.x86_64 12/15
Verifying : policycoreutils-2.2.5-11.el7_0.1.x86_64 13/15
Verifying : libsemanage-2.1.10-16.el7.x86_64 14/15
Verifying : audit-2.3.3-4.el7.x86_64 15/15
Installed:
policycoreutils-python.x86_64 0:2.2.5-20.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.4.1-5.el7
checkpolicy.x86_64 0:2.1.12-6.el7
libcgroup.x86_64 0:0.41-8.el7
libsemanage-python.x86_64 0:2.1.10-18.el7
python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.7-46.el7
Dependency Updated:
audit.x86_64 0:2.4.1-5.el7 audit-libs.x86_64 0:2.4.1-5.el7
libsemanage.x86_64 0:2.1.10-18.el7 policycoreutils.x86_64 0:2.2.5-20.el7
Complete!
Start using semanage command on your CentOS 7 and RHEL 7 systems.
Hope this helps.
Recommended read:
- How To Find The Package That Provides A Specific File In Linux
- Find If A Package Is Available For Your Linux Distribution
- Suggest Installation Of Packages When Running An Unavailable Command
- How To Check Linux Package Version Before Installing It
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
9 comments
Thank you for providing a solution. Super easy to follow.
Thank you! I needed semanage after changing my webroot to a nonstandard path.
yum install policycoreutils-python
Worked for me. Thank you
Thanks!
worked for my machine also … Terima kasih pak!
I was able to type
yum provides semanage
and come up with the same results.
I guess you typed /usr/sbin/semanage to limit the number of results, but is there a way the end user would know the ultimate path of that program to be able to anticipate that?
Hi, usually the the executables are located in /usr/sbin and /usr/bin and /usr/local/bin directories. Hence, we can search directly in these locations.
Thank you very much; that was an awesome very easy to follow article that solved my problem