LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to make cifs run as root (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-cifs-run-as-root-303635/)

cdavidson 03-19-2005 02:48 PM

how to make cifs run as root
 
I've been Googling for a while now and I haven't found the answer to this yet, so I was hoping the good folks at LQ could lend a hand. I'm working on mounting shares from a W2K3 server on my FC3 workstation. I can mount the shares with no problem by executing:

mount -t cifs //servername/sharename /mnt/windows -o user=username,password=pwd

from a terminal as root. I put the same line in my /etc/fstab file to execute at bootup, but I get a message saying "line number x is bad in /etc/fstab". I'm assuming that this is because the command must be run as root, which it is not doing at boot up. My questions are these:

1. How can I make the above command run as root at bootup in my /etc/fstab?
2. I want to take my UN and PWD out of the command and use a credentials file. I created a file, /etc/credentials, with the syntax of:

username=un
password=pwd

I tried executing:

mount -t cifs //servername/sharename /mnt/windows -o credentials=/etc/credentials

from a terminal as root, but my syntax is off somewhere, and the man pages weren't much help to me. Once I can get the command to run as root at bootup, what should the proper syntax be to use the command with a credentials file? Thanks in advance.

cylix 03-19-2005 03:21 PM

mount -t smbfs -ousername=blah,password=blah //machinename/share /mnt/location

cdavidson 03-19-2005 03:59 PM

Thanks for the reply cylix. I started out trying to use SMBFS, but there is apparently a problem between it and W2K3 shares. Whenever I try to mount the shares using SMBFS, I get the following:

cli_negprot: SMB signing is mandatory and we have disabled it.
17906: protocol negotiation failed
SMB connection failed

I have added "client signing=yes" to my globals in my smb.conf file, but that doesn't fix the problem. After a long conversation with Google, it told me to use cifs. This would be perfect if I could just figure out how to make it run as root at bootup in my /etc/fstab. Anyone got any ideas?

CD

cylix 03-19-2005 06:16 PM

Gotcha,

Must have misread that... don't worry... I'm going to correct my mistake or at least try..

If you are getting an error message in your logs about needing root access to mount.

chmod +s /path/to/mount.cifs

If you had to put in your own mount.cifs utility you probably want to make sure it's in the executable path or just along side the mount utility. Mount will call the mount.whatever and it doesn't need compiled against it. (checked just to be sure)

So your fstab line should look like this... I use vi so no newline spill over occurs. *fstab varies a bit from the mount stuff... so you need to make sure you make it all happy.

//share/name /mount cifs defaults,credentials=/path/to/credentials/file 0 0

note, you will absolutely need to make sure it runs as root before hand.

mount -t cifs -ocredentials=/path/to/file //share/name /mnt

At least, in my case I had to use smbfs because I have no 2003 box lying around. *I know, I need to sit down with it*

cdavidson 03-19-2005 08:27 PM

thanks again cylix...

I ran "chmod +s /sbin/mount.cifs" on my system. I got the following syntax to work from a terminal as root:

mount -t cifs //server/share /mnt/windows -o credentials=/etc/credentials

I also made /etc/credentials readable only by root, chmod 700 /etc/credentials, as root. During bootup, i'm still getting the error message "line 9 in /etc/fstab is bad", ditto for the other 3 mount commands in my fstab file. Is there not a way to make fstab execute as root at startup, or is that not even my problem? Is there another startup file, .bashrc maybe???, that i can add the commands to that will execute properly?

I know...I know I'm a :newbie: , I'm working on it though.

cylix 03-19-2005 08:44 PM

Someone didn't look at my fstab line closely.

It's not a root related issue (I don't know why mount wouldn't be running as root, but I thought to use that just in case)

If you fire up vi /etc/fstab it should highlight elements not syntactly correct. (at least if you have ansi color on and it's really vim and not that aged vi)

It should be something precisely like this....

"//servername/share /mnt/point cifs defaults,credentials=/etc/credentials 0 0"

The only difference between here and my fstab, all spaces are tabs except when I get to 0 0, but any whitespace should be fine. Also, make sure the target directory exists.

+S is the setuid bit, so when the binary is executed it is ran as the owner of the file. (in this case we did setuid on both owner and group, which was a little overboard) Just make sure mount.cifs is owned by root and if that is still a worry, you could always do the same for mount (just for testing now)

But the error you are describing I reproduced quite well on my first stab entries. It's a syntax error purely.

Additionally, you don't have to reboot.

Just issue a mount -a

This will mount all things listed in the fstab file.

cdavidson 03-19-2005 10:03 PM

:D Many thanks cylix, that did the trick :D . One question though :Pengy: ...I was always able to succesfully execute:

mount -t cifs //server/share /mnt/windows -o credentials=/etc/credentials

from the terminal. Is there a specific reason that the same syntax wouldn't work from fstab, possibly that fstab just has to have that certain syntax? Either way, thanks again...

cylix 03-19-2005 10:32 PM

The short answer is yes....

when called by sysinit, mount -a and a few other options are all that are called.

Simply, when mount was written, the code that parses the /etc/fstab file is different. Certain things are implicit *like not needing to mention mount* and all the options are parsed by column. (or really white space)

So there are literally two different sections of code for applying options. One section deals with information coming in as arguements on the command line and another section is called when the -a option is provided.

so when parsing options by file, you can save a great deal of time to simply knowing knowing where your data is going to be. Additionally, mount isn't the only tool which uses the fstab file. Utilities to dump the file system to archive also reference the fstab file. ala 0 0 (which are actually directives for the dump utility and any one else who cares to use them).

This is advantageous because you can now store meta parameters for other applications in a bit of a central location.

There are other applications for this as well, but I think this covers the basics.

I had to write a utility that accepted input from standard in, arguements and a configuration file. Trust me, I saved time wherever I could.


All times are GMT -5. The time now is 08:46 AM.