使用Java Runtime.getRuntime.exe()打开文件夹给出超级用户凭据

发布于 2025-01-24 08:38:26 字数 246 浏览 4 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2025-01-31 08:38:26

我已经回答了自己的问题。意识到问题不是运行时方法,而是开放命令本身。打开命令起源于 https://www.freedesktop.org/wiki/ 从外部程序调用时调用sudo命令。因此,解决方案是用非root用户覆盖sudo

Runtime.getRuntime.exec("sudo -u pi open /home/pi/data)

-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

Runtime.getRuntime.exec("sudo -u pi open /home/pi/data)

the -u command allows you to set the user, and pi is the default user on the RPi distro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文