-   Linux - Newbie (
-   -   Mounting Samba share in fstab (

deity_me 09-19-2011 05:01 PM

Mounting Samba share in fstab
I've been reading some guides how to mount a samba share from an fstab and I have a question.

I want to add it to the fstab
but I want it to prompt me for a username/password
can this be done?

The guides I've read all put the user/pass in the fstab or in a credentials file.
I want it to ask me for the user/pass when I try to mount it myself.


T3RM1NVT0R 09-19-2011 06:16 PM

@ Reply
Hi there,

As far as I am aware it is not possible without mentioning username and password in /etc/fstab or without using credential file. The reason being during startup it reads the /etc/fstab file and mount the partitions on the basis of it.

The processess cannot be halted to put in the password. The best you can do is to create a script which contains the command to mount samba share (just mention the username there not the password) and call that script via /etc/rc.local.

I hope this helps.

deity_me 09-19-2011 11:02 PM

One more minor question
How do you mount the share as read/write?
This is the command I'm using to mount

mount -t cifs //server/share /mountpoint -o rw,username=myuser

I know I setup the server properly because I can mount it from my Mac and create folders.
When I mount it on my Linux, I get permission denied.


T3RM1NVT0R 09-20-2011 03:07 PM

@ Reply
You can mount the share as read/write if in the backend you have specified that share is writable. This is something you need to do in Samba backend. If you have shared a directory via Samba as read only then you cannot write to it.

For the "Permission denied" error the syntax is a bit different. The one you mentioned is:


mount -t cifs //server/share /mountpoint -o rw,username=myuser
As I mentioned before if share access control is defined in backend. No need to mount it using -o rw. The correct syntax is:


mount -t cifs //server/share /mountpoint -o username=domain_name/myuser


mount -t cifs //server/share /mountpoint -o username=workgroup_name/myuser
When you are mounting the share you should specify the domain name or the workgroup name as described above.

I hope this helps.

deity_me 09-21-2011 05:19 PM


Thanks for the help

I was actually able to get it as read/write by adding


I dont know what this is but it worked.


T3RM1NVT0R 09-21-2011 05:56 PM

@ Reply
Glad to hear that the issue has been resolved!

Could you please mark the thread as solved.

PTrenholme 09-21-2011 08:25 PM

Just a brief comment: Adding the mount to rc.local would, I believe, not be an effective way to get a "Password?" prompt, since rc.local is run, as "root," by the init script. I just use a .smb_credentials file in my $HOME directory. Since that's a hidden file, and I deny read to group and others, only I (or "root") can access the file.

I suspect that you may be resisting using a credentials file is because you suspect that it may compromise your security, but if nobody but you (and "root") can read the file, I don't think that there's much compromised. Even if someone reads the name in fstab, they will still not be able to read the file. (You'd use something like chmod go-rwx .smb_credentials command to set the file permissions so only you could access that file. See man chmod for details.)

durus123 11-23-2011 01:57 PM

It is possible to mount the Samba share in the fstab. I did this on a RHEL 4 box and Samba 3.0.

I created a file with the username and password, and protected it with permissions 600. I also made it a dot file, /root/.sambapass just for a bit more obscurity. So my .sambapass looked like:

username = test
password = test123

Then my entry in the fstab file looked like:

//grape/testshare /mountpointname smbfs credentials=/root/.sambapass,uid=apache,gid=apache
grape - Windows box
testshare - Windows share name
mountpointname - where you want the share mounted

The uid and gid are valid on the Linux box. They don't have to be related to any domain account name.

Hope this helps.

Cathy Smith

All times are GMT -5. The time now is 08:27 PM.