仅向特定应用程序授予文件夹的写入权限
我正在使用 crontab 在 Linux 服务器上运行 java 代码,我想将此代码抛出的所有消息和异常记录到 /var/log/myapplog/ 目录内的文件中。我已经编写了记录器类。
但我想确保只有这段代码可以创建文件并写入该目录中的文件。是否有一个命令可以代替向所有人授予写权限(chmod 777
)?
谢谢
I am using crontab to run a java code on a linux server and I want to log all messages and exceptions thrown by this code to a file inside /var/log/myapplog/ directory . I have already written the logger class.
But i want to make sure that only this piece of code may create files and write to files inside this directory. Is there a command for this instead of giving write permissions to all (chmod 777
) ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最可靠的方法是以唯一可以写入此目录的用户身份运行程序。创建一个用户
myapp
,运行chown myapp /var/log/myapplog
和chmod 755 /var/log/myapplog
(或700
),并在crontab
中使用su
为程序授予适当的权限。如果程序需要不同的权限,您可以考虑将记录器拆分到不同的进程中。
The surest way is to run the program as the only user that may write to this directory. Make a user
myapp
, runchown myapp /var/log/myapplog
andchmod 755 /var/log/myapplog
(or700
), and usesu
in thecrontab
to give the program the proper permissions.If the program needs different permissions, you might consider splitting the logger out into a different process.