How to mount/umount disk from a non-root account

Thread Tools Search this Thread
Operating Systems Linux How to mount/umount disk from a non-root account
# 1  
Old 03-05-2008
How to mount/umount disk from a non-root account

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?
# 2  
Old 03-06-2008
No way to workaround that - such commands are explicitely obligation of root account with a reason. You can use "sudo" for example to call :


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 

            BufferedReader stdError = new BufferedReader(new 

            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {

replace "ps -ef" with "sudo mount $parameters"
# 3  
Old 03-06-2008
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.

# 4  
Old 03-06-2008
I've edited the /etc/fstab and added user option

/dev/loop1              /storage/part1          auto    noauto,user,noexec 0 0

My version of mount/umount is:
[brendan@rubidium /]$ mount -V
mount: mount-2.12a

I can mount ok as user root, but ordinary user gets:

[brendan@rubidium ~]$ mount /dev/loop1 /storage/part1 -o user
mount: only root can do that

Is this a bug perhaps?

Sudo prompts for password, using Java runtime exec, this is not an option.

Setting suid bits may be the way to go if all else fails Smilie

Last edited by brendan76; 03-06-2008 at 01:48 PM..
# 5  
Old 03-06-2008
[mount problem]

It's strange - I'm using:
mount: mount-2.12p

I can't test it now, but can you check permissions to file which you want to mount?


I'm sure you can configure sudo without asking for a password. As far as I remember I did it long time ago.


I don't recommend it.

# 6  
Old 03-07-2008
If I edit /etc/sudoers and add:


Then as user brendan execute:

sudo mount /dev/loop1 /storage/part1

This works fine, but is there any long term problems, etc. in doing this?
# 7  
Old 03-07-2008
Have you check permissions to file which you want to mount on loopback? I havn't seen any comment about it.

Regarding sudo configuration - it's not the best idea to provide access for ALL commands, you can choose a list which is required by you.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Test cases for file system mount/umount performance in HP

Hi Folks, Could anyone please assist me with the what could be the scenarios to test the file system mount/umount performance check in HPUX. Thanks in advance, Vaishey (5 Replies)
Discussion started by: Vaishey
5 Replies

2. Fedora

What is the right way to mount and umount a usb driver?

I have some questions: 1, I successfully mounted my usb drive with "sudo mount /dev/sdb1 /mnt", but I can't wirte, It says "read-only file system". But I can write it in windows. 2, After I umounted the usb drive the led of it still on, but not blinking. Is it safe to unplug it? How to let it's... (17 Replies)
Discussion started by: vistastar
17 Replies

3. UNIX for Dummies Questions & Answers

Simple way to umount NFS mount in linux

Hello... I've mounted a share using standard nomenclature for the NFS mount command with the following command line: mount -t nfs -o rw {IP address1}:/ /mnt_for_70 / {IP address2}(rw) mnt_for_70 is a mount point I created on {IP address2} I'm confuse and want to be sure I use the... (1 Reply)
Discussion started by: blaine.miller
1 Replies

4. Cybersecurity

Remove need for sudo for mount/umount

Hello, I'm trying to remove the need to use sudo to mount (in particular, binding). Modifying /etc/sudoers using visudo, I have tried: %admin ALL=NOPASSWD: /usr/bin/mount %admin ALL=NOPASSWD: /usr/bin/umountand %admin ALL=(ALL) NOPASSWD: /usr/bin/mount %admin ALL=(ALL) NOPASSWD:... (5 Replies)
Discussion started by: Narnie
5 Replies

5. Solaris

mount & umount in sigle-user mode

In Solaris 8, when I boot to single user mode, mount a device and then reboot or init 0, the system unmount it automatically. However, in Solaris 10 it does not seem to do the same. Here is what I did: {0} ok boot -s # format Searching for disks...done AVAILABLE DISK SELECTIONS: 0.... (11 Replies)
Discussion started by: StarSol
11 Replies

6. UNIX for Dummies Questions & Answers

How to mount disk for non-root accounts?

I have a USB disk on a little NAS controller (NSLU2 running unslung 6.8) that I can access nicely with root with mount -t cifs \\\\\\DISK\ 2 /mnt/LKGD7F73A However, when I run emacs from an user mode xterm prompt, emacs cannot read and write the files on /mnt/LKGD7F73A. Emacs can... (11 Replies)
Discussion started by: siegfried
11 Replies

7. UNIX for Dummies Questions & Answers

How to mount disk for non-root accounts?

Presently I have mounted a disk as su. I believe only root can mount disks -- is this correct? I had to run mozilla in the root account so I can download the new SuSE distribution to the new disk. How can I mount the disk so non-root accounts can access the disk? Thanks, Siegfried (4 Replies)
Discussion started by: siegfried
4 Replies

8. UNIX for Dummies Questions & Answers

How do i access (mount, read & write) a floppy disk from the console, not being root?

welll, the title quite explains what i want to do thanks for your time! (4 Replies)
Discussion started by: kfaday
4 Replies

9. UNIX for Dummies Questions & Answers

solaris 8 admin I text ambiguities on mount and umount

i'm prepping for my midterm, which i will bomb. i am scurrying to finish reading the final chapter before i get down into the review. however, i came across something in chapter 8 - "mounting file systems" that has me really confused. the text says the following: then it goes on to... (2 Replies)
Discussion started by: xyyz
2 Replies

10. UNIX for Dummies Questions & Answers

Writing a script to mount and umount a drive in Linux

I have a 1 GB jazz drive. The jazz disk is used daily, both at home and at work on my Win 98 Server. So, I have to keep it in vfat format, which is fine because Linux rocks and will read it no problem. :-) However, I can't just stick the disk in the drive and open up the jazz folder in my mnt... (2 Replies)
Discussion started by: wizkid
2 Replies
Login or Register to Ask a Question

Featured Tech Videos