Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run jar with root privileges on mac os x by one click

Tags:

jar

root

jpcap

I implemented a small java sniffer-tool with jpcap. So far its functioning fine, but it needs root privileges to get access to the network-devices. In case of I export my project to a runnable jar, I can run it by using sudo in terminal:

$ sudo java -jar littleSniffer.jar 

Does anyone knows a "one click"-solution to run my runnable jar with root privileges. I want to give that tool to my workmates, and it would be nice I they could start it without using the terminal. Maybe by using the automator app?

like image 818
Philipp Li Avatar asked Aug 11 '13 20:08

Philipp Li


People also ask

How do I run as root in Mac terminal?

To run commands with superuser privileges, use the sudo command. sudo stands for superuser do. You're asked for the password of the current user. You're asked to enter the password for adminUsername, after which a new shell is opened for that user.


1 Answers

Try something like this:

If you are happy with terminal, just create a new file and put in something like this:

#!/bin/sh
sudo java -jar littleSniffer.jar

and save the file as blah.command (the .command extension runs the sh file in terminal on double click).

If you would like something a bit nicer, you could use the osascript command like this:

#!/bin/sh
osascript -e "do shell script \"java -jar littleSniffer.jar\" with administrator privileges"

Which will use a GUI request for the root password.

NOTE: If your .command file isn't running, you may need to:

chmod +x blah.command

to make it runnable.

like image 125
Ed M Avatar answered Oct 27 '22 22:10

Ed M