Operating System - Linux
1753730 Members
4705 Online
108799 Solutions
New Discussion юеВ

enable mount for ordinary user ?

 
Piotr Kirklewski
Super Advisor

enable mount for ordinary user ?

mount -t cifs -o username=administrator,password=xxx //10.25.1.1/backup /data
mount: only root can do that

[user@xxx]$ mount user

[user@xxx]$ mount: can't find user in /etc/fstab or /etc/mtab

[user@xxx]$ uname -a
Linux xxx 2.6.18-194.26.1.el5 #1 SMP Tue Nov 9 12:54:20 EST 2010 x86_64 x86_64 x86_64 GNU/Linux

How to sort that out ?
Jesus is the King
6 REPLIES 6
Mel Burslan
Honored Contributor

Re: enable mount for ordinary user ?

I am having hard time understanding what you are trying to do here. The first command :

mount -t cifs -o username=administrator,password=xxx //10.25.1.1/backup /data

is failing because, as a non-root user, you do not have mount privileges.

On the second command failing :

mount user

you are trying to mount a filesystem named user and there is no such filesystem to start with, but if there were one, you would get the same error message as you got on the first one.

I am sure you have the sudo utility installed by default (if not, install it using a method convenient to you), then, create a script with the mount command that you want placed in it, and give permission to run this script as root user to the person you want running it.

After installing sudo, check the man page to figure out how to accomplish this, or just simply edit the /etc/sudoers file and see the examples. It is really simple
________________________________
UNIX because I majored in cryptology...
Alzhy
Honored Contributor

Re: enable mount for ordinary user ?

Is your fileserver (10.25.1.1 in your example) capable of doing NFS (v2/3/4)?

If so, autofs (NFS automounter) may just be what the doctor prescribed.
Hakuna Matata.
Piotr Kirklewski
Super Advisor

Re: enable mount for ordinary user ?

man mount says this :

...user Allow an ordinary user to mount the filesystem. The name of the mounting user is written to
mtab so that he can unmount the filesystem again. This option implies the options noexec,
nosuid, and nodev (unless overridden by subsequent options, as in the option line
user,exec,dev,suid).

So no - I am not trying to mount anything here. I'm just trying to change the option so everyone can mount this share, but for some reason it doesn't work:

[user@xxx]$ mount: can't find user in /etc/fstab or /etc/mtab

So let me repeat the question:
How do I enable mount for a non-root user?

[user@xxx]# cat /etc/fstab

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0

[user@xxx]# cat /etc/mtab
/dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/sda1 /boot ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
Jesus is the King
Mel Burslan
Honored Contributor

Re: enable mount for ordinary user ?

That changes the picture. Edit /etc/fstab and add the line below

##############
10.25.1.1/backup /data cifs rw,users,owner,noauto,username=administrator,password=xxx
##############

anything between two lines containing ############## goes into one single line in case forum screen limits split them into two, separated by space(s) or tab(s)

Be aware that I am not sure about the use of username=blah,password=blah in the options. If it the system complains, take them out and provide them from command line as you initially did, but the phrase "users" is the one you are looking for. This string of options, separated by comma (",") replaces the defaults on the lines which are in your fstab right now.

Hope this helps

________________________________
UNIX because I majored in cryptology...
Matti_Kurkela
Honored Contributor

Re: enable mount for ordinary user ?

There are four mount options which can authorize a non-root user to mount a filesystem in Linux:

- user
- users
- owner
- group

Although they are listed on the mount(8) man page, these options make sense only when added to /etc/fstab.

In Mel's example, both "users" and "owner" are used - this is incorrect. One of them is enough.

"users" allows any user to mount the filesystem, and once mounted, any user can also unmount it.

"user" allows any user to mount the filesystem, but only root or the user who mounted it can unmount it.

"owner" allows the owner of the device file to mount or unmount that filesystem.

"group" allows mounting or unmounting the filesystem if the user is a member of the group the device file belongs to.

The last two are not appropriate for NFS or CIFS mounts: there is no device file.

When mounting a CIFS filesystem as a regular user, the user must own the mount-point directory or the mount will fail.

The /sbin/mount.cifs must be setuid root, or the ordinary users won't be able to mount CIFS filesystems at all.
(chown root /sbin/mount.cifs; chmod u+s /sbin/mount.cifs)

/etc/fstab must usually be readable by everyone, so putting passwords in it is not a good idea. Instead, the "cred=" option allows putting the username and password into a separate file, which you can protect with more restrictive permissions.

To avoid the password prompt, you will also need the option "guest".

It's likely you'll also need the option "dom=" to specify the workgroup/domain name you're using for Windows authentication.

For more information about available options when making CIFS mounts, please read "man mount.cifs".

This is how I would do it:
############
//10.25.1.1/backup /data cifs rw,noauto,users,dom=domain,cred=/somewhere/backup.cred,guest 0 0
############

And the contents of the file /somewhere/backup.cred should look like this:

############
username=administrator
password=xxx
############

Once all this is set up, the ordinary user (that owns the /data directory) can mount and unmount this CIFS share using the short form of the mount/umount commands:

mount /data
umount /data

By the way, using the Windows administrator account for CIFS mounts like this is bad for security: you should have the Windows administrator create a separate account with appropriate privileges for this purpose.

MK
MK
Piotr Kirklewski
Super Advisor

Re: enable mount for ordinary user ?

So is this what my /etc/fstab should look like ? It still doesn't work.

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
//10.25.1.1/backup /data cifs rw,noauto,users,cred=/root/backup.cred,guest 0 0
Jesus is the King