简体   繁体   中英

How to run Sudo code without password in mac

I want to run "sudo rm ing /tmp/instruments_sock" in terminal. I am doing this through code using robotil jar. But I am not able to enter password. Is there any way that I run this command without asking for password in mac.!! I want to remove password ONLY for this command.

If you want to perform a single privileged task without a password, the best way is probably to use a setuid binary.

In short, you make a tiny program that does what you want. You then give the program root privileges by setting its owner to root and enabling the setuid bit.

A very important warning : Don't just call system("rm /tmp/something") in your setuid binary! That is a classic security bug. Unclean environment variables (such as PATH) can hijack the command. There's a short introduction to the security problem in the wikipedia link above.

Instead of using system(), the easiest and safest way is to use the language's own file handling libraries. If you aren't 100% sure about what you are doing, avoid running shell commands from your binary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM