systemctl 无法访问服务文件,权限被拒绝

systemctl 无法访问服务文件,权限被拒绝

在 Fedora 35 上,我创建了自己的服务来安排备份。我的脚本位于 /usr/local/bin/ 中,服务文件和计时器位于 /lib/systemd/system/ 中

ls -an /usr/local/bin/ 打印

-rwxr--r--. 1 0 0 3360 Dec 1 18:31 backup.sh

ls -an /lib/systemd/system/schedule-backup_root*

-rw-r--r--. 1 0 0 230 Dec  1 18:14 /lib/systemd/system/schedule-backup_root.service
-rw-r--r--. 1 0 0 388 Dec  1 16:49 /lib/systemd/system/schedule-backup_root.timer

但是当我启动服务 systemctl start Schedule-backup_root.service

Dec 01 18:36:13 fallen-robot systemd[1]: Started Nightly snapshot backup job for ROOT volume.
Dec 01 18:36:13 fallen-robot systemd[75159]: schedule-backup_root.service: Failed to locate executable /usr/local/bin/backup.sh: Permission denied
Dec 01 18:36:13 fallen-robot systemd[75159]: schedule-backup_root.service: Failed at step EXEC spawning /usr/local/bin/backup.sh: Permission denied
Dec 01 18:36:13 fallen-robot systemd[1]: schedule-backup_root.service: Main process exited, code=exited, status=203/EXEC
Dec 01 18:36:13 fallen-robot systemd[1]: schedule-backup_root.service: Failed with result 'exit-code'.

我的服务文件如下所示:

[Unit]
Description=Nightly snapshot backup job for ROOT volume

[Service]
Type=simple
ExecStart=/usr/local/bin/backup.sh -s / -b /run/media/borko/BackupTest/ -t "Fallen Robot ROOT Backup Report"

[Install]
WantedBy=default.target

为什么无法访问该文件?

答案1

禁用 SElinux 或将其设置为宽松。

setenforce 0

这将暂时禁用它。禁用后再次测试,看看是否可以解决问题。

相关内容