13

Whenever I'm trying to execute this line to configure SELinux to install xrdp from this tutorial:

# chcon --type=bin_t /usr/sbin/xrdp
# chcon --type=bin_t /usr/sbin/xrdp-sesman

I get these errors:

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'

I'm on CentOS 7.2 64 bit.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
TheOnlyOne
  • 133
  • 1
  • 1
  • 4

3 Answers3

11

I'm also on CentOS 7, and this works for me:

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
Thinh Phan
  • 119
  • 2
  • 4
  • 1
    While Thomas gave a pretty comprehensive answer, the solution is not that straightforward. I had to do a lot of try and error till I reached these two commands, which are actually working – Adelin Feb 13 '18 at 10:19
  • That worked for me too in a CentOs box. – ramires.cabral Apr 27 '20 at 19:39
5

Your command has to give more information. It has been discussed before (but I see no duplicates).

For example,

For example, ls -lZ gives these tags for a sample listing:

$ 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

and chcon is expecting something like unconfined_u:object_r:bin_t:s0 in its argument. A bin_t is only partial information.

The referenced procedure should have worked, and the use of chcon redundant. Checking my CentOS7, I happen to have xrdp installed, and a listing shows

$ 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

The system_u field is the SELinux user, the object_r field is the role, bin_t is the type and s0 is the (default) level. The files in /usr/sbin get their context from a pattern shown by semanage fcontext -l (but there are a lot of matches). In following the guide, you may have removed the pattern for the xrdp — or even for /usr/sbin. However, you can be more explicit in the command, by specifying the user and role using 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

Alternatively, if the patterns are intact but (for instance) you had moved the files rather than installing them, you could repair things using

restorecon -v /usr/sbin/xrdp
restorecon -v /usr/sbin/xrdp-sesman

Further reading:

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • 3
    I still don't get it , Can you tell me what command would be the fix for it then ? as I'm not really familiar with linux Neither SELinux :( – TheOnlyOne Apr 05 '16 at 14:57
4

It might help someone, so here is my simple 2 cents. If you somehow disabled selinux, you might face this issue. to resolve this, just change the selinux back to normal. open /etc/selinux/config and change

SELINUX=disabled

back to

SELINUX=enforcing

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227