简体   繁体   English

Linux RPM安装软件包脚本无法更改所需文件的所有权

[英]Linux RPM install package script failure to change ownership of required file

Testing usage of RPM install package shell script. 测试RPM安装软件包shell脚本的用法。

Have included linux commands within the shell script to create a new user and change ownership of /etc/hosts to that user. 在外壳程序脚本中包含了linux命令,以创建一个新用户并将该用户的/ etc / hosts所有权更改为该用户。 Shell script content: Shell脚本内容:

useradd bob
chown bob /etc/hosts

Post RPM install this should result in: RPM安装后,这应导致:

-rw-r--r--. 1 bob root 331 Jan  4 11:13 /etc/hosts

Instead after RPM install completion it remains: RPM安装完成后,它仍然是:

-rw-r--r--. 1 root root 331 Jan  4 11:13 /etc/hosts

/etc/hosts is owned by root so chances are the script doesn't have privileges to alter that file. /etc/hostsroot拥有,因此该脚本没有更改该文件的特权。

I'm not sure how you are executing the script, however if it's just a standard shell script you could try sudo : 我不确定您如何执行该脚本,但是如果它只是一个标准的shell脚本,则可以尝试sudo

sudo ./my_script.sh

(Caveat: changing ownership of system-level files like this is a security issue and not the smartest idea.) (注意:像这样更改系统级文件的所有权是一个安全问题,而不是最明智的主意。)

Are you sure the script is run? 您确定脚本已运行吗? You may want to make the first line: 您可能想做第一行:

useradd bob || /bin/true

or just 要不就

useradd bob || :

so that it always returns true. 因此它总是返回true。 Otherwise rpm will abort the script if, for example, the user "bob" already exists. 否则,例如,如果用户“ bob”已经存在, rpm将中止脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM