Is it possible to mount a disk from a non-root account?
I'm developing a Java application which executes commands in the shell using the java.lang.Runtime.exec api, which runs fine for commands ls, df, etc., but for commands mount and umount, i have problems as I need to be root to eecute these. But my application must run as a standard out of the box.
Any ideas on getting mount/umount running from my non-root user account?
No way to workaround that - such commands are explicitely obligation of root account with a reason. You can use "sudo" for example to call :
import java.io.*;
public class RunCommand {
public static void main(String args[]) {
String s = null;
try {
// run the Unix "ps -ef" command
Process p = Runtime.getRuntime().exec("ps -ef");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
If you can define earlier which resources you want to mount/unmount using your application it can be added to /etc/fstab with user option (allow a user to mount).
You can configure sudo for it as well.
Dirty method - add suid bits to mount/umount command and try to manage access using groups.
For user mounts the user or users option needs to be put in fstab thus indicating that root approved the configuration. And the user must use only one parameter in the mount command... this is not a license to specify a different mount point. With "user" only the user who mounted (or root) can umount it later. With "users", anyone can umount.