Java execute Linux commands that require su?

倖福魔咒の 提交于 2019-12-25 05:08:05

问题


What is the best way to run Linux commands that require "su" with Java? I want it to be very reliable, as for security goes I don't care much about it the system is not a production server. No one ever connects to the machine but myself. I thought about logging in as root so I don't have to deal with the su command and its disabled by default. I'm using Debian 6.

The only thing is that one of my requirements is that the program should start after the normal user logs in without any farther user input. I would set auto login for the normal user and when the computer is turned on and after the normal user logs in I would want that Java program to run as sudo, su without any user input. Would that be possible?

Please tell me a simple and reliable solution.

Regards


回答1:


Use sudo instead. It can be configed to allow specific command run without typing in password.




回答2:


For running programs that require root access, they should be run with sudo. The user will be asked to enter a password. As mentioned in the previous answer, sudo can be used to configure commands to be run as root that do not require entering a password. Try looking at the man page for sudo for more information regarding that.

If you want to run programs on system startup, you can write a bash script to run the command gksudo java -jar path when the user logs in. This will prompt the user with a dialog box to enter a password.

I also recommend doing a system call at the beginning of the program to ensure root access.



来源:https://stackoverflow.com/questions/11143027/java-execute-linux-commands-that-require-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!