当前位置: 首页 > 知识库问答 >
问题:

linux - executable path is prefixed with "!":!的含义是 ?

尤祖鹤
2023-08-26

安装motion后:

cat  /lib/systemd/system/motion.service | grep !ExecStartPre=!/bin/mkdir -p /var/log/motionExecStartPre=!/bin/chown motion:adm /var/log/motion

参看手册https://www.freedesktop.org/software/systemd/man/systemd.serv...

"+" If the executable path is prefixed with "+" then the process is executed with full privileges. In this mode privilege restrictions configured with User=, Group=, CapabilityBoundingSet= or the various file system namespacing options (such as PrivateDevices=, PrivateTmp=) are not applied to the invoked command line (but still affect any other ExecStart=, ExecStop=, … lines). However, note that this will not bypass options that apply to the whole control group, such as DevicePolicy=, see systemd.resource-control(5) for the full list.
Similar to the "+" character discussed above this permits invoking command lines with elevated privileges. However, unlike "+" the "!" character exclusively alters the effect of User=, Group= and SupplementaryGroups=, i.e. only the stanzas that affect user and group credentials. Note that this setting may be combined with DynamicUser=, in which case a dynamic user/group pair is allocated before the command is invoked, but credential changing is left to the executed process itself.

阅读了,还是有点不明白,有哪位再详细解释一下?

共有1个答案

马朝斑
2023-08-26

大概就是这样的,+!都表示用特权用户(root)执行后面的命令,但是+-的强化版本,+会忽略PrivateDevices=, PrivateTmp=等等一些权限限制,而!不会忽略。

这里推荐一下金步国翻译的systemd文档:https://www.jinbuguo.com/systemd/systemd.service.html#

做了一个实验:

写了一个service:

[Unit]Description=httpb ServerAfter=network.target[Service]User=abcd          # 使用abcd用户执行这个服务Group=abcdPrivateTmp=true     # 开启私有tmp目录,为了测试ExecStartPre=/usr/bin/whoami       # 不指定参数的情况下查看当前用户,和创建文件 cc.txtExecStartPre=/usr/bin/touch /tmp/cc.txtExecStartPre=!/usr/bin/whoami      # 使用!执行命令和创建文件 aa.txtExecStartPre=!/usr/bin/touch /tmp/aa.txt  ExecStartPre=+/usr/bin/whoami       # 使用+执行命令和创建文件 bb.txtExecStartPre=+/usr/bin/touch /tmp/bb.txtExecStartPre=/usr/bin/ls -lah /tmp   # 不指定参数查看/tmp目录下的文件信息ExecStartPre=+/usr/bin/ls -lah /tmp   # 使用+参数查看/tmp目录下的文件信息ExecStart=/usr/bin/python3 -m http.server 8002   #忽略WorkingDirectory=/opt/httpbRestart=always[Install]WantedBy=multi-user.target

因为文档上说了!号相比+号,少了PrivateTmp这个权限,所以就用PrivateTmp来做实验。

开启了PrivateTmp后,启动的服务,会创建一个临时的/tmp目录,并且挂载在/tmp/systemd-private-bb77789941f8428aa599931e5be5e923-httpb.service-L9w8fg/tmp目录下。

分别写了三组whoamitouch文件,然后使用ls -lah /tmp查看创建的文件。

执行后的结果如下:

Aug 25 16:52:52 debian whoami[25898]: abcdAug 25 16:52:52 debian whoami[25900]: rootAug 25 16:52:52 debian whoami[25902]: rootAug 25 16:52:52 debian ls[25904]: total 8.0KAug 25 16:52:52 debian ls[25904]: drwxrwxrwt  2 root root 4.0K Aug 25 16:52 .Aug 25 16:52:52 debian ls[25904]: drwxr-xr-x 18 root root 4.0K Aug 21 15:33 ..Aug 25 16:52:52 debian ls[25904]: -rw-r--r--  1 root root    0 Aug 25 16:52 aa.txtAug 25 16:52:52 debian ls[25904]: -rw-r--r--  1 abcd abcd    0 Aug 25 16:52 cc.txtAug 25 16:52:52 debian ls[25905]: total 40KAug 25 16:52:52 debian ls[25905]: drwxrwxrwt 10 root root 4.0K Aug 25 16:52 .Aug 25 16:52:52 debian ls[25905]: drwxr-xr-x 18 root root 4.0K Aug 21 15:33 ..Aug 25 16:52:52 debian ls[25905]: drwxrwxrwt  2 root root 4.0K Aug 21 15:28 .ICE-unixAug 25 16:52:52 debian ls[25905]: drwxrwxrwt  2 root root 4.0K Aug 21 15:28 .Test-unixAug 25 16:52:52 debian ls[25905]: drwxrwxrwt  2 root root 4.0K Aug 21 15:28 .X11-unixAug 25 16:52:52 debian ls[25905]: drwxrwxrwt  2 root root 4.0K Aug 21 15:28 .XIM-unixAug 25 16:52:52 debian ls[25905]: drwxrwxrwt  2 root root 4.0K Aug 21 15:28 .font-unixAug 25 16:52:52 debian ls[25905]: -rw-r--r--  1 root root    0 Aug 25 16:52 bb.txtAug 25 16:52:52 debian ls[25905]: drwx------  3 root root 4.0K Aug 21 15:33 systemd-private-bb77789941f8428aa599>Aug 25 16:52:52 debian ls[25905]: drwx------  3 root root 4.0K Aug 25 16:52 systemd-private-bb77789941f8428aa599>Aug 25 16:52:52 debian ls[25905]: drwx------  3 root root 4.0K Aug 21 15:33 systemd-private-bb77789941f8428aa599>Aug 25 16:52:52 debian systemd[1]: Started httpb Server.

没有带参数的ls -lah,只有 aa.txt 和 cc.txt ,没有发现bb.txt
然后有带+ls -lah,显示了主机/tmp目录下的文件,也看到了bb.txt文件,说明使用+和文档上说明是一致的,会忽略PrivateTmp=这个设置。

 类似资料:
  • 问题内容: 我试图了解课堂 它是的可选构造函数参数 和 这也是的强制性参数。 根据我已阅读的信息,我可以写一些论文 a)对于PhantomReference方法,get始终返回null b) 对于Phantom引用: 1. gc检测到可以从内存中删除 该对象2. 当我们从队列中调用clear或link到引用的引用时,引用了放置到ReferenceQueue的对象,因为无法访问并且gc看到了3. f

  • 问题内容: $ time ./Test 这是程序代码: 问题答案: 如果您查看联机帮助页(),它会指出: time命令使用给定参数运行指定的程序命令。命令完成后,时间将消息写入标准输出,以提供有关此程序运行的计时统计信息。这些统计信息包括(i)调用和终止之间经过的实时时间;(ii)用户CPU时间(由times(2)返回的结构tms中tms_utime和tms_cutime值的总和),以及(iii)

  • 问题内容: 我在Android源代码中看到一个陌生的符号: 例如: 我对星号表示法不熟悉。有人可以解释吗? 问题答案: 是的简化版本 此表示法来自C。

  • 问题内容: 我想知道我是否使用值为8的INT,这是否意味着我只能从1到99999999或从1到4294967295 UNSIGNED? 问题答案: 该文档对此似乎很清楚: 数值类型属性 MySQL支持扩展,可以选择在整数类型的基本关键字之后的括号中指定整数数据类型的显示宽度。例如,INT(4)指定显示宽度为四位数的INT。应用程序可以使用此可选的显示宽度来显示整数值,该整数值的宽度小于为列指定的宽

  • 问题内容: 我正在写一个类,表示一个二维向量。我存储和在。 当要求生成和时,eclipse生成了以下内容: 什么是意义在这方面?我不能简单地写吗? 问题答案: 简短答案:Eclipse使用 Double.doubleToLongBits, 因为这就是Double.equals的作用: 结果是,当且仅当参数不是,并且是一个Double对象,该对象表示与该对象表示的值相同的e 。为此,当且仅当该方法应

  • 我一直在网上关注关于SQLite的android教程。我有一份声明,我不确定: 在这个方法中,意味着什么?它是当前对象还是上下文?谢谢