The*_*One 12 linux selinux centos
每当我尝试执行此行以配置 SELinux 以安装本教程中的xrdp 时:
# chcon --type=bin_t /usr/sbin/xrdp
# chcon --type=bin_t /usr/sbin/xrdp-sesman
Run Code Online (Sandbox Code Playgroud)
我收到这些错误:
chcon: can't apply partial context to unlabeled file '/usr/sbin/xrdp'
chcon: can't apply partial context to unlabeled file '/usr/sbin/xrdp-sesman'
Run Code Online (Sandbox Code Playgroud)
我在 CentOS 7.2 64 位上。
小智 7
我也在 CentOS 7 上,这对我有用:
chcon -h system_u:object_r:bin_t:s0 /usr/sbin/xrdp
chcon -h system_u:object_r:bin_t:s0 /usr/sbin/xrdp-sesman
Run Code Online (Sandbox Code Playgroud)
您的命令必须提供更多信息。之前已经讨论过(但我没有看到重复)。
例如,
semanage.chcon命令中使用完整类型(但您必须首先使用 确定类型ls -Z)。完整类型:的名称中通常会有一个冒号 ( ),因为它代表一个层次结构。例如,ls -lZ为示例列表提供这些标签:
$ ls -lZ msginit msgmerge msgunfmt
-rwxr-xr-x. root root unconfined_u:object_r:bin_t:s0 msginit
-rwxr-xr-x. root root unconfined_u:object_r:bin_t:s0 msgmerge
-rwxr-xr-x. root root unconfined_u:object_r:bin_t:s0 msgunfmt
Run Code Online (Sandbox Code Playgroud)
并且在其论点中chcon期待类似的东西unconfined_u:object_r:bin_t:s0。Abin_t只是部分信息。
所引用的程序应该已经工作了,并且使用了chcon冗余。检查我的 CentOS7,我刚好xrdp安装了,并显示一个列表
$ ls -lZ xrdp xrdp-chansrv xrdp-sesman xrdp-sessvc
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp-chansrv
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp-sesman
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp-sessvc
Run Code Online (Sandbox Code Playgroud)
该system_u字段是 SELinux用户,该object_r字段是角色,bin_t是类型,s0是(默认)级别。中的文件/usr/sbin从semanage fcontext -l(但有很多匹配项)显示的模式中获取它们的上下文 。在遵循指南时,您可能已经删除了xrdp- 甚至/usr/sbin. 但是,您可以在命令中更加明确,通过使用chcon以下命令指定用户和角色:
chcon -u system_u -r object_r --type=bin_t /usr/sbin/xrdp
chcon -u system_u -r object_r --type=bin_t /usr/sbin/xrdp-sesman
Run Code Online (Sandbox Code Playgroud)
或者,如果模式完好无损,但(例如)您移动了文件而不是安装它们,则可以使用
restorecon -v /usr/sbin/xrdp
restorecon -v /usr/sbin/xrdp-sesman
Run Code Online (Sandbox Code Playgroud)
进一步阅读:
restorecon - 恢复文件默认 SELinux 安全上下文。chcon - 更改文件 SELinux 安全上下文