# Add a SMB mount to /etc/fstab

## KraziKid

I am trying to add my Windows share to /etc/fstab and am running into problems.  My username on my windows machine consists of my first name follwed by my last name, for example, "Krazi Kid" (no quotes).  When I do a manual mount using the mount command, and put my username in quotes, it works.  Now, when I try to do this in fstab, I get an error saying that the line is bad.  How can I get this to work?

----------

## splooge

Don't know if this will work for ya but maybe try using a \

eg

Krazi\ Kid

----------

## KraziKid

I should have mentioned, I already tried escaping the space, it still didn't work.

----------

## WarMachine

I just added a user account to my windows system to use for this, seemed a simpler solution.  If you use XP and the welcome screen and you don't want the name there install tweakUI to remove it from that list.

----------

## caffiend

try putting your login info into a file as such...

/etc/samba/credentials (this file should be only readable by root)

```
username = Krazi Kid

password = my_password
```

then in /etc/fstab

```
//server/mountpoint /local/path smbfs credentials=/etc/samba/credentials 0 0
```

see if it will work without the quotes, if not try it with them.

----------

## KraziKid

Thank you.  That works prefectly.

----------

## d0wn_under

A couple of questions as extensions to this discussion:

1 - How do I setup the fstab so that a user can mount their own home directory (not automounting)? Obviously I can't setup a fstab line for each user specifying the mount point.

2 - the server.credentials file has been mentioned here and in other posts. I created one and put my username and password in it then made it only readable by root. The problem I then got was that ordinary users trying to do the mount got an error that they could not read the file. Changing the permission to all read allowed the users to come closer to mounting, this time getting the error:

Operation not permitted

root can do the mount fine, any other user can't. Also, if root mounts the share, he can write to it but ordinary users can't.

Here is my fstab entry:

//192.168.0.4/temp  /mnt/ttemp      smbfs credentials=/etc/server.credentials,noauto,rw,user,umask=000,gid=100   0 0

and my smb.conf lines:

[temp]

        comment = Temp Share

        path = /tmp

        guest ok = yes

        writable = yes

        share modes = no

Anyone any ideas on either of these?

Ta

Robin

----------

## stillman

a little late but here's an answer for 2.:

simply use the uid-option, e.g. uid=1000, that's all - here's my smb-line in fstab:

```
//192.168.0.1/tmp    /home/shared    smbfs credentials=/etc/samba/credentials,uid=1000,gid=100 0 0
```

that works fine(running edonkey-tempfolder with this share)

thank you for the credentials-solution - surprisingly i didn't find it when i searched forced, but found it accidentally now  :Very Happy: 

----------

## d0wn_under

Still not quite there I now get:

cannot mount on /mnt/ttemp: Operation not permitted

smbmnt failed: 1

when a non-root user tries to mount it. I tried the line you gave me and also tried adding a "user" option to the list, both without success.

The directory I'm trying to mount it on is writable by the user, the directory being mounted is at least readable (probably writable as well) by the user but still no luck.

root can mount the share ok and then any other user can access it so the mount works and the stuff to allow other users access, just not other users mounting.

As an extra idea I also tried making the credentials file world readable for a while to see if it was that but it wasn't.

Any other ideas?

----------

## PowerFactor

I don't think you can have normal users mount samba shares without using sudo or something.  Setting smbmount suid root might work but it's probably not a good idea.  Smbmount doesnt seem to obey the user option in fstab.  To allow each user to mount their home directory in the windows box I would use a script something like this.

```
#!/bin/sh

mount -t smbfs -o  \ 

     credentials=${HOME}/.samba/credentials,uid=${SUDO_UID},gid=${SUDO_GID} \

     //192.168.0.1/${SUDO_USER} /mnt/${SUDO_USER}
```

Then setup sudo to allow the users to run that script.  I haven't tried that script exactly so there may be some errors, but you can see point I think.  And of course you would need to use sudo for the unmounting as well.

EDIT:  (Ignore this, see edit2)Well I just tried and it doesn't look like sudo will work either.  I just tried to mount a share with sudo and I get a "Access denied, SMB Connection failed" error.  That's with the exact same command that just worked as root. Just a pure hardcoded command, no variables or anything like I have above.  Any ideas?

EDIT2: My bad, sudo does work. It helps to spell credentials right. :Embarassed: 

----------

## d0wn_under

But till then, at work, as an ordinary user with no sudo I can mount any shares I want. This is on a standard debian install.

I've checked the sudoers file and there is nothing in there that would affect it. I wouldn't have thought that debian would suid something like mount but I may try it here.

I've tried asking the sysadmin and claims ignorance as to why it works, he is just happy it does.

Updates later...

----------

## stillman

sorry, didn't read you'd want to mount smb as non-root...

----------

## HolyCoitus

I found this in another post when I was looking for a similar problem with mounting a share folder that had a space in it, hopefully this can help someone:

 *Oo.et.oO wrote:*   

> from man fstab:
> 
>  *Quote:*   If the name of the mount point contains spaces these can be escaped as `\040'. 
> 
> this, of course, works for the device as well (in this case the smb share)
> ...

 

----------

## d0wn_under

It is now all working, ta to everyone who suggested ideas.

 :Laughing: 

----------

## phunni

I have an interesting problem - I followed some of the steps above (namely using the credentials file) and I can now mount a samba share as a normal user - but I'm not allowed to umount it!

Any ideas on this one?

Here is my /etc/fstab:

 *my /etc/fstab wrote:*   

> /dev/hda1		/boot		ext3		noauto,noatime		1 1
> 
> /dev/hda3		/		reiserfs	noatime,notail		0 0
> 
> /dev/hda2		none		swap		sw			0 0
> ...

 

----------

## tank

 *d0wn_under wrote:*   

> It is now all working, ta to everyone who suggested ideas.
> 
> 

 

How did you get it working?  I am trying to do the exact samething and running into the same problems you have.

Did you use sudo?

----------

## Vlad

It is possible to have a user mount smb shares.  Here's how.

1.  Make sure you have an appropriate line in your /etc/fstab file for the share you wish to mount.  This is well documented enough for me not to explain it here (not to mention it's been explained in posts above).  Just a heads up: you MUST have "users" in your mount options for this to work!

2.  If your mount path is going to be "/mnt/windows_share", then you *must* own it to mount it. 

# chown vlad:users /mnt/windows_share

3. The program smbmnt MUST be SUID.  I'm sure this is a possible security hazard, so use at your own risk.

# chmod +s /usr/sbin/smbmnt

Troubleshooting:

If you're still getting this error:

cannot mount on /mnt/windows_share: Operation not permitted

smbmnt failed: 1

Then you haven't put "users" in your mount options in the /etc/fstab file, or you haven't chown'ed the mount path to your username.

If you see:

smbmnt must be installed suid root for direct user mounts (101,101)

smbmnt failed: 1

Then you haven't chmod +s /usr/sbin/smbmnt.  (101 refers to your UID).

Hope this helps sombody.  I have no idea how to allow multiple users to mount the same share, so don't ask, as I have a single user system.

----------

## d0wn_under

What do you do with your login credentials (i.e. passwords)?

I've got mine in a file which I started off with as owned and only readable by root, the problem I had was that when I used my ordinary user, even though smbmnt was running as root it couldn't read the file so I ended up making the user own the file which on my single user system is ok but in a multi-user environment isn't ok.

The alternative, putting the username and password in fstab creates the same problem, it has to be open for reading by most users but that then reveals the passwords to all.

The way we get round it at work is to provide the username and password as parameters to mount which means each user can have their own username and password but there has to be a different way, this is the all flexible linux isn't it  :Smile: 

Any ideas?

----------

## Redneck

On my setup, /etc/fstab is chmodded 600 and owned by root:root and I can mount with a normal user (who gets a Permission denied when trying to 'cat /etc/fstab')

Maybe this info helps

(Althou  I cannot unmount the damn share :))

----------

