# 出现useradd cannot set SELinux context for home directory怎么办

By [wlxzhang](https://paragraph.com/@walixz) · 2022-09-07

---

但是如果使用的是CentOS 7系统，而且Linux内核版本在2.6及以上，添加用户时指定用户家目录时，会出现错误提示：

    useradd: cannot set SELinux context for home directory /tmp/xiaoming
    

无法创建的原因是SELinux机制处于开启状态，需要关闭，具体操作如下：

查看SELinux（Linux的安全机制）当前的状态

临时关闭

永久关闭

    vim /etc/sysconfig/selinux
    disabled - No SELinux policy is loaded.
    SELINUX=disabled
    SELINUXTYPE= can take one of three two values
    

![](https://storage.googleapis.com/papyrus_images/bb92f7ed377769b4a3b91055f2a56a023ccb52ec1bf458aca8f40a9329a19a99.png)

解决方法很简单，将SELinux的工作模式临时切换到宽容模式，然后再添加新用户指定家目录，最后再切换回强制模式。

参考文章：[useradd cannot set SELinux context for home directory解决办法](https://walixz.com/useradd-selinux-problem.html)

---

*Originally published on [wlxzhang](https://paragraph.com/@walixz/useradd-cannot-set-selinux-context-for-home-directory)*
