$linuxjunkies
>

semanage(8)

Manage SELinux policy components including users, roles, types, and file contexts.

UbuntuDebianFedoraArch

Synopsis

semanage SUBCOMMAND [OPTIONS] [-h]

Description

semanage is the primary tool for managing SELinux policy at the user level without requiring policy recompilation. It handles persistent modifications to SELinux configuration including user mappings, role definitions, port access, interface bindings, and file context rules.

Changes made with semanage are stored in the SELinux policy store and persist across reboots. The tool supports subcommands for managing users, roles, types, booleans, logins, ports, interfaces, modules, and file contexts.

Most subcommands require root privileges. Use -h with any subcommand for detailed help on that specific operation.

Common options

FlagWhat it does
-a, --addAdd a new entry (used with subcommands like user, role, port, fcontext)
-m, --modifyModify an existing entry
-d, --deleteDelete an existing entry
-l, --listList all entries of the specified type
-C, --clearClear all customizations and restore defaults
-S, --seuserSpecify the SELinux user for login mappings
-t, --typeSpecify the SELinux type context
-r, --rangeSpecify the MLS/RBAC security range
-p, --protoSpecify protocol type (tcp or udp) for port rules
-s, --sourceSource type for interface bindings

Examples

List all file context rules currently in the policy

semanage fcontext -l

Add a file context rule so /var/www/myapp and its contents are labeled httpd_sys_rw_content_t

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/myapp(/.*)?' 

Allow SSH connections on custom port 2222

semanage port -a -t ssh_port_t -p tcp 2222

List all Linux user to SELinux user mappings

semanage login -l

List all SELinux users and their role assignments

semanage user -l

List all SELinux booleans with their current states

semanage boolean -l

Remove HTTP port 8080 from policy

semanage port -d -t http_port_t -p tcp 8080

Modify existing file context rule for /home/admin

semanage fcontext -m -t admin_home_t '/home/admin(/.*)?'

Related commands