Automatically Mounting SMB Shares in Ubuntu Linux

  1. This article is outdated!

    I have written a new post with a better mounting method. Please read my new Mounting Windows SMB Shares v3 post before trying anything in this one.

ubuntu-small.jpg

After my move to Ubuntu I was finding the built in network browser very slow. I decided to see if there was a way I could mount my SMB shares to the /media directory so they show up as a drive on the desktop. Better yet, I wanted to make it so they mount automatically on boot.

First you have to install smbfs:

sudo apt-get install smbfs

Then create a folder inside of the /media directory to mount the share on:

sudo mkdir /media/Storage

then you can run the following command to mount a share manually:

sudo mount -t smbfs //fileserver/Storage /media/Storage -o uid=USER,gid=users

Note: Change USER to your linux username. The uid=USER,gid=users is important because if you dont use that, only root will have access to write files to the mounted share.

Or you can edit the mount list in /etc/fstab to have the drive mount on boot

sudo gedit /etc/fstab

And add this line to the bottom of the fstab file, but change //fileserver/Storage to the path to your share on your server.

//fileserver/Storage /media/Storage smbfs credentials=/home/USER/.smbcredentials,uid=USER,gid=users 0 0

In the above line change USER to your user account in both spots. Before this will work you also have to create the .smbcredentials file in the above users home directory.

sudo gedit ~/.smbcredentials

Add the following information to the file, but change Guest to your SMB username and add your SMB password.

username=Guest
password=

Note: My fileserver allows Guest access to the shares, so I just use the username Guest with no password. If your server requires a username and password put it in here.

To test if the auto mount works just run the following command

sudo mount -a

You should see a new mount show up on your desktop for the drive.

If you are worried about people who dont have root access being able to read login and password from the .smbcredentials file you can give only root and admin group access by typing

sudo chmod o= ~/.smbcredentials

Note: Do not try and mount a folder on a share, it wont work. The source for an SMB mount has to be a share.

Note: Do not put a trailing “/” on the share path or the directory path, it will cause it to fail.

SMB Shares with spaces in the names

If you have an SMB share with a space in the path you can replace the space with \040. For example:

//fileserver/Storage\040Share /media/Storage\040Share smbfs credentials=/home/USER/.smbcredentials,uid=USER,gid=users 0 0

Change USER to your linux username. This will mount the share “//fileserver/Storage Share” to the directory “/media/Storage Share” and give USER r/w access to it. If you are using the mount command you dont have to do this, you can just put the source share and the destination directory into quotes like this:

sudo mount -t smbfs "//fileserver/Storage Share" "/media/Storage Share" -o uid=USER,gid=users

12 Responses to “Automatically Mounting SMB Shares in Ubuntu Linux”

  1. fear of mice Says:

    Automatically Mounting SMB Shares in Ubuntu Linux

    My new Kubuntu Breezy install wouldn’t play my MP3s which are stored on a remote Samba share though local MP3s were fine.

    The above link supplies a HOWTO to fix this. Basically set up the SMB share with a local mount point, stuff it in etc/fstab to …

  2. tramdol Says:

    I always have terrible trouble with comment-related plugins that require me to put some line in the comment loop; I can never seem to find the right spot. Can anyone tell me where I should put the php line in my comments loop? I haven not modified anything much, and I would be very grateful. Thanks!

  3. James Mason Says:

    Thanks, worked as advertised on Feisty…

  4. Chris Says:

    Thanks for this - it worked like a charm. Guides like this rock!

  5. shaheem sadien Says:

    hi, i´ve been looking for help on the space issue for a while. thanks

  6. p00Bah Says:

    Thank you, thank you, thank you.

    Your post was easy to follow, easy to understand, and worked like a charm!

  7. quas-klchrittrodrifter Says:

    Works Fine on Feisty!

    Thx

    I had trouble a few hours with that problem…

  8. tr0stvik Says:

    Hmmm, i don’t get this to work.. i’m on a ubuntu laptop and trying to connect to a gentoo server on the network.. the server is using samba with logon(smbusers). It is working perfectly from windows, but not from this laptop. I can get it to work with read-only, but not rw.

    The command i use is: mount -t smbfs -o username=USER,password=XXX //IP/USER /home/USER/raid uid=USER,gid=USER

    Yes, offcourse… user, password and ip is all changed in the real one.

    I don’t get an error, i get the Usage lists, etc…

  9. Matt Says:

    I dont know if this method works anymore. It might be outdated. I’m currently using cifs instead of smbfs. If I have a chance this weekend I’ll post an update.

    In fact, I did update this in November of ‘06, but I use an even different method than that.

    You can find the updated article here:
    http://www.mattvanstone.com/2006/11/automatically_mounting_smb_sha_2/

  10. Zac Krebs Says:

    Just thought I’d drop in and leave a comment.

    This method works in ubuntu 7.04 perfectly. Every time my wireless network connected, the share would mount. I used it to listen to music from my other server.

    I recently upgraded to 7.10. This does NOT auto-mount, I had to say mount all to get it all to work. No idea why…but hey, thanks for the article.

  11. Jo Says:

    Worked, ubuntu 7.10 connecting to a freecom network drive. Thanks!

  12. German Rincon Says:

    It worked. Thanks!!

Leave a Reply