The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to mount disk for non-root accounts? siegfried UNIX for Dummies Questions & Answers 11 03-17-2007 10:36 PM
How to mount disk for non-root accounts? siegfried UNIX for Dummies Questions & Answers 4 08-28-2006 05:47 AM
How do i access (mount, read & write) a floppy disk from the console, not being root? kfaday UNIX for Dummies Questions & Answers 4 05-13-2005 12:17 PM
solaris 8 admin I text ambiguities on mount and umount xyyz UNIX for Dummies Questions & Answers 2 10-10-2002 09:57 AM
Writing a script to mount and umount a drive in Linux wizkid UNIX for Dummies Questions & Answers 2 05-10-2001 07:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-05-2008
brendan76 brendan76 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
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 (permalink)  
Old 03-06-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
No way to workaround that - such commands are explicitely obligation of root account with a reason. You can use "sudo" for example to call :


Code:
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);

replace "ps -ef" with "sudo mount $parameters"
  #3 (permalink)  
Old 03-06-2008
Artur Zaworski Artur Zaworski is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
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.

Regards,
-Artur.
  #4 (permalink)  
Old 03-06-2008
brendan76 brendan76 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
I've edited the /etc/fstab and added user option


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

My version of mount/umount is:

Code:
[brendan@rubidium /]$ mount -V
mount: mount-2.12a

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


Code:
[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

Last edited by brendan76; 03-06-2008 at 01:48 PM..
  #5 (permalink)  
Old 03-06-2008
Artur Zaworski Artur Zaworski is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
[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?

[sudo]

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

[suid]

I don't recommend it.

Regards,
-Artur.
  #6 (permalink)  
Old 03-07-2008
brendan76 brendan76 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
If I edit /etc/sudoers and add:


Code:
brendan ALL=NOPASSWD: ALL

Then as user brendan execute:


Code:
sudo mount /dev/loop1 /storage/part1

This works fine, but is there any long term problems, etc. in doing this?
  #7 (permalink)  
Old 03-07-2008
Artur Zaworski Artur Zaworski is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
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.

Regards,
-Artur.
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0