
genhomedircon Command in Linux
genhomedircon is a command-line utility in Linux that stands for "generate home directory contexts". It is used in SELinux (Security-Enhanced Linux) to create or update SELinux context labels for user home directories based on the SELinux policy.
In this tutorial, we will discuss the use of the genhomedircon command in Linux along with examples. Also, we will illustrate how to install it on different Linux distributions if it is not already installed.
Table of Contents
Here is a comprehensive guide to the options available with the genhomedircon command −
- How to Install genhomedircon Command?
- How to Enable SELinux?
- How to Check if the genhomedircon Command is Installed?
- How to Use genhomedircon Command in Linux?
- How to Access the Manual Page of the genhomedircon Command?
- How to Remove genhomedircon Command from Linux?
How to Install genhomedircon Command?
The genhomedircon command belongs to the SELinux utilities and is only available if SELinux is installed and configured on your system. You can use one of the following commands to install it on different Linux distributions −
#for Debian-based distributions sudo apt install selinux-utils #for the latest versions of Fedora, CentOS, or RHEL sudo yum install policycoreutils-python #for Arch Linux sudo pacman -S yay yay -S selinux
Since we are using Ubuntu 24.04, so we use apt to install genhomedircon on our system −

Alternatively, you can run the following command to install genhomedircon command in Linux −
sudo apt install policycoreutils

How to Enable SELinux?
If you are unable to access the genhomedircon command after installation, you need to enable selinux. To enable SELinux on Ubuntu, first, install the necessary SELinux packages using the command −
sudo apt install selinux-basics selinux-policy-default

Now configure SELinux by executing the following command −
sudo selinux-activate
The output shows that SELinux has been successfully activated −

Now reboot the system for SELinux to take effect and to avoid unwanted circumstances −
sudo reboot
After restarting your system, run the following command to check the status of SELinux and to ensure it's enabled and running in enforcing mode −
sestatus
The output shows that SELinux is enabled on our Ubuntu 24.04 −

Now you are all set to use the genhomedircon command in Linux.
How to Check if the genhomedircon Command is Installed?
We can use the âwhichâ command, âcommand -vâ, or âtypeâ command to confirm the existence of the genhomedircon command on our system. Letâs run each command one by one −
which genhomedircon
This command will show the path to the genhomedircon if it's properly installed on your system. However, if it's not installed, the cursor will move to the new line without displaying anything −

Similarly, you can confirm the installation of the genhomedircon command in Linux using the âcommand -vâ, and âtypeâ command, as follows −
command -v genhomedircon type genhomedircon

How to Use genhomedircon Command in Linux?
The genhomedircon command updates the active SELinux policy without reloading it. It also assigns labels to user home directories based on paths from getpwent(). To do this, you can set the "usepasswd" setting in â/etc/selinux/semanage.confâ to "true" (by default). Usually, this script runs automatically with semanage. However, you can turn it off by setting "disable-genhomedircon" to "true" in the configuration file. You can also exclude certain directories from labeling by using the "ignoredirs" option.
To use the genhomedircon command in Linux, you must follow the below-given syntax −
genhomedircon [ -d selinuxdir ] [-n | --nopasswd] [-t selinuxtype ] [-h]
Letâs understand how this command works with the specified options −
Option | Description |
---|---|
-d selinuxdir | It specifies the SELinux directory where the configuration files are located. |
-n | --nopasswd] | It generates contexts without prompting for passwords. |
-t selinuxtype | It sets the SELinux type for the home directory that is being created. |
-h | It shows the basic help regarding the genhomedircon command. |
To use the genhomedircon command in Linux, login as a sudo user, type genhomoedircon in the terminal, and hit the enter key. As a result, it will scan the â/etc/passwdâ file for user home directories and apply the suitable SELinux context to them −
sudo genhomedircon
How to Access the Manual Page of the genhomedircon Command?
You can use the following command to access the manual page of the genhomedircon command for a deeper understanding −
man genhomedircon

How to Remove genhomedircon Command from Linux?
If genhomedircon is no longer needed, you can run one of the below-given commands to uninstall it from your system −
#for debian-based systems sudo apt remove selinux-utils sudo apt remove policycoreutils #for Red Hat-based systems sudo yum remove policycoreutils #for debian-based systems sudo pacman -R policycoreutils
This sums up the use of the genhomedircon command in Linux.
Conclusion
The genhomedircon command is a useful utility in SELinux-enabled Linux systems. It manages the security contexts of user home directories by applying the correct SELinux labels. This is essential for maintaining system security.
In this tutorial, we covered how to install and enable genhomedircon on various Linux distributions. We also explained how to verify its installation. Additionally, we explored the command's options and provided examples of its usage.