使用Java Runtime.getRuntime.exe()打开文件夹给出超级用户凭据
我有一个Java应用程序,该应用程序可以通过文件夹打开一个文件夹
Runtime.getRuntime.exec("open /home/pi/data")
,并且在文件夹打开时可以使超级用户访问。如果我只是
open /home/pi/data
从命令行中运行,则可以提供正常的访问权限。我不仅对如何阻止这种情况发生感兴趣,还对它发生的原因感兴趣。
I have a java application that opens a folder via
Runtime.getRuntime.exec("open /home/pi/data")
and it gives super user access when the folder opens. If I just run
open /home/pi/data
from the command line it gives normal access. I am not only interested in how to stop this from happening but also why it is happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经回答了自己的问题。意识到问题不是运行时方法,而是开放命令本身。打开命令起源于 https://www.freedesktop.org/wiki/ 从外部程序调用时调用sudo命令。因此,解决方案是用非root用户覆盖sudo
-U命令允许您设置用户,而PI是RPI发行版上的默认用户。
I have answered my own question. After realizing that the issue was not with the Runtime method but rather the open command itself. The open command originates from https://www.freedesktop.org/wiki/ and seems to automatically invokes the sudo command when called from an external program. So the solution is to override the sudo with the non root user
the -u command allows you to set the user, and pi is the default user on the RPi distro.