【发布时间】:2017-10-07 15:27:20
【问题描述】:
为了配置我的 CentOS 系统,我想覆盖一个任意文件,该文件几乎保留了除时间戳和内容之外的所有属性。
例如,我将使用/etc/phpMyAdmin/config.inc.php
注意:被复制的文件在其他文件系统中
[root@localhost phpMyAdmin]# ls -laZ /etc/phpMyAdmin/
drwxr-x---. root apache system_u:object_r:etc_t:s0 .
drwxr-xr-x. root root system_u:object_r:etc_t:s0 ..
-rw-r-----. root apache system_u:object_r:etc_t:s0 config.inc.php
[root@localhost phpMyAdmin]# /bin/cp -frv --backup=numbered --preserve=mode,ownership,context,xattr config.inc.php /etc/phpMyAdmin/config.inc.php
«config.inc.php» -> «/etc/phpMyAdmin/config.inc.php» (respaldo: «/etc/phpMyAdmin/config.inc.php.~1~»)
[root@localhost phpMyAdmin]# ls -laZ /etc/phpMyAdmin/
drwxr-x---. root apache system_u:object_r:etc_t:s0 .
drwxr-xr-x. root root system_u:object_r:etc_t:s0 ..
-rw-r-----. root apache system_u:object_r:unlabeled_t:s0 config.inc.php
-rw-r-----. root apache system_u:object_r:etc_t:s0 config.inc.php.~1~
[root@localhost phpMyAdmin]# systemctl restart httpd
当我尝试http://localhost/phpmyadmin 时,我第一次收到 SELinux 警告,而 Apache 无法访问该文件。
[root@localhost phpMyAdmin]# chcon --reference /etc/phpMyAdmin/config.inc.php.~1~ /etc/phpMyAdmin/config.inc.php
[root@localhost phpMyAdmin]# ls -laZ /etc/phpMyAdmin/
drwxr-x---. root apache system_u:object_r:etc_t:s0 .
drwxr-xr-x. root root system_u:object_r:etc_t:s0 ..
-rw-r-----. root apache system_u:object_r:etc_t:s0 config.inc.php
-rw-r-----. root apache system_u:object_r:etc_t:s0 config.inc.php.~1~
[root@localhost phpMyAdmin]# systemctl restart httpd
现在 apache 可以读取文件了。
如何让 cp 保留原始文件的 SELinux 上下文?
【问题讨论】:
标签: linux phpmyadmin cp selinux