[英]How do you set user work as root in Linux, when the bash script runs via Java code
Suppose my bash file contains 假设我的bash文件包含
chmod -R 777 $backup_files/app/webroot/uploadedFiles/
It works fine when I run it through root permission using /permission.sh
but when I try to run this bash script via java code like 当我使用/permission.sh
通过root权限运行它时,它运行良好,但是当我尝试通过Java代码(例如,
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("/permission.sh");
printBufferedReaderOutputFromProcess(process);
process.waitFor();
It gives me the following error: 它给了我以下错误:
chmod: changing permissions of `/home/app/webroot/uploadedFiles/A.jpg': Operation not permitted
What can I fix it? 我该如何解决?
I suspect you haven't use sudo before, however an alternative to using the setuid on the script is to give the user the right to sudo the script as root. 我怀疑您以前没有使用过sudo,但是在脚本上使用setuid的另一种方法是赋予用户以root身份对sudo脚本进行操作的权利。 ie 即
sudo permisions.sh
This runs as root can can be run without asking a password. 以root用户身份运行,无需输入密码即可运行。 You have to set this up in sudoers.conf 您必须在sudoers.conf中进行设置
How are you running your Java code? 您如何运行Java代码? Is it stand-alone, or running in a web container like Tomcat? 它是独立的,还是在像Tomcat这样的Web容器中运行? If the later, it's probably running as a user that doesn't have permissions to the directory you're trying to change. 如果是更高版本,则它可能以没有您要更改目录权限的用户身份运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.