chcon:无法将部分上下文应用于未标记的文件“/usr/sbin/xrdp”

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)


Tho*_*key 5

您的命令必须提供更多信息。之前已经讨论过(但我没有看到重复)。

例如,

例如,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/sbinsemanage 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)

进一步阅读:

  • 我还是不明白,你能告诉我什么命令可以解决它吗?因为我不太熟悉 linux 也不熟悉 SELinux :( (3认同)