sudoless无密码脚本 文件权限无密码的rsync

问题描述

我想制作一个无须密码的脚本,它不会提示执行该脚本的任何用户输入密码。

问题:我的脚本包含rsync实用程序,用于将文件发送到备份服务器,但是当需要发送的文件夹包含一些文件时,我总是会收到permission denied error access设置为无。而其他文件也由root拥有,但是它们的access设置为只读。我正在使用公共密钥身份验证将文件发送到目标/备份,以便它不提示输入密码,但是如果没有sudo和密码输入,它将无法像上面一样发送受访问保护的文件

尝试:我尝试过https://unix.stackexchange.com/a/229653/332764解决方案,但没有用。还有同样的错误

编辑: sudoers文件

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

ortega ALL=(ALL) nopASSWD: /home/usr/path/transmit_ckpnt.sh
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

解决方法

您有几种选择:

  1. 设置root crontab作业以执行chown(必须具有root定期执行的作业)
  2. 使用docker privilege escalationchmod将文件放在已装入卷的容器中。
  3. 设计与您正在执行的根目录等效的非根任务

1。根crontab

crontab计划在指定的时间或时间间隔执行命令。在这里,您可以使用命令sudo crontab -u root -e创建一个root crontab。这将使您进入编辑器以编写crontab:best practices

2。 Docker权限升级

此方法需要已经root或已经成为docker group机器的一部分。作为docker组成员的非root用户,您可以将任何目录作为卷安装在docker容器中。在容器中,您是root用户,对安装的卷所做的更改将保留。只需chmod容器中的文件即可。

文件权限

无密码的rsync

  • rsync命令支持使用ssh-keys,它使您可以在一次快速的密钥交换后以无密码的方式登录到其他计算机。

如果由于权限错误而无法chownchmod文件,这是因为具有比您(根)用户更多权限的用户将需要帮助您更改文件权限。