Automatically Mounting Windows SMB Shares in Ubuntu v3
This post is an update to two posts I wrote previously on how to make your network shares mount automatically when you start up your Ubuntu Linux computer. In this method we modify the fstab file so that when all the file systems are mounted the network shares are mounted as well.
This method works for me in Ubuntu Gusty Gibbon 7.10 and is probably the most secure. I have only tested this on a wired connection, so I don’t know exactly what will happen if you use this method when using a wireless connection.
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
You can call it whatever you want, I call it Storage. If you change the name remember to change it below when we edit the fstab file.
Create a credentials file in /root so that you can save your password and have it protected by the root account:
sudo gedit /root/.cifscredentials
Add the following information to the file, but change Guest to your SMB username and add your SMB password.
username=Guest password=
Note: If your fileserver allows Guest access you can just leave the file as above. If it is password protected you have to put in your username and password.
Save and close the .cifscredentials file.
Now open up your fstab file so that you can add mounting instructions:
sudo gedit /etc/fstab
Add the following line to the bottom of the file:
//192.168.0.10/SHARENAME /media/Storage cifs auto,iocharset=utf8,uid=USER,gid=users,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0
You have to change the following information:
Change 192.168.0.10 to the IP address or DNS name of your server
Change SHARENAME to the share you want to mount
Change USER to your Ubuntu username
The file_mode=0775,dir_mode=0775 part sets the mounted directory as read/write for all users so long as the SMB username you set in .cifscredentials has read/write access.
Now save the file and run the following command to test to see if you mount now works:
sudo mount -a
If that worked you should see a new drive icon on your desktop that lets you access your share. Now try rebooting and see if your shares mount automatically. If everything went as planned you will have a nice little drive mounted on your desktop every time you start up.
SMB Shares with Spaces in the Names
If you have a share with a space in the path you can replace the space with \040. For example:
//192.168.0.10/Storage\040130 /media/Storage\040130 cifs auto,iocharset=utf8,uid=matt,gid=users,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0
This mounts my 130GB drive on my fileserver to a local directory called Storage 130.




November 11th, 2007 at 10:29 am
[...] This article is out of date. I have written a new post for a better method. Please read my new post before trying anything in this one Mounting Windows SMB Shares v3. [...]
November 11th, 2007 at 10:37 am
[...] 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 [...]
November 22nd, 2007 at 5:25 am
Is mounting the share in fstab instead of an init script necessarily BETTER? What if the share is unreachable - won’t that prevent the machine from booting, if it cannot mount the drives listed in fstab?
November 25th, 2007 at 8:24 pm
In my experience if the drives are inaccessible then it just shoots back an error code and continues booting.
I read a comment from a guy who said when he put his shares in his fstab file they connected automatically when he connected to wireless. I have not tested this out but that could be one benefit over a startup script.
November 27th, 2007 at 2:53 am
Thanks for this! I’ve been looking for a while now for a way to do this.
I wanted to know, is it possible to have the share mount in your home folder, so that is shown in the places menu (in ubuntu)?
December 6th, 2007 at 9:21 pm
Thats a good question… I dont know, I’ve never tried myself. I would assume you could mount at any point by changing the /media/ path to whatever you want. I’ll give that a try.
December 8th, 2007 at 7:50 am
Worked ok for me (7.10) but I still had to use SMB instead of CIFS with my Freecom Network Drive.
December 8th, 2007 at 1:19 pm
In Kubuntu Gutsy,
Main Menu->System Settings->Advanced (Tab)->Disk & Filesystems->Administrator Mode->New->Browse->Network Folders->Browser Shares->Samba Shares->(Select Share)
Check ‘Enable At Startup’
You may still have to install the samba software, I’m not sure if that was out of the box or if I did it myself.
December 9th, 2007 at 9:45 pm
Thanks! Exactly what I was looking for
December 10th, 2007 at 11:03 am
Thanks a bunch man, couldn’t get my drive to mount until i read your directions!
January 10th, 2008 at 12:44 pm
These worked great for me!
A question: what if I want to do the same with a networked Linux partition? I have a Linksys NSLU2 attached to my network, is it just a matter of replacing the cifs in fstab with smbfs??>
January 27th, 2008 at 11:28 pm
Useful & Clear, Thank you.
February 16th, 2008 at 10:05 pm
Hey man, thanks for a great how to. Miserable weather we are having here in calgary.
Ever since a permanently mounted my networked shares, i get an error when i restart my pc. Basically it hangs and displays a bunch of text about it having tried to close connections and cfs… something to that effect? Does this affect you too?
February 18th, 2008 at 11:23 am
How would you modify this procedure if wanted to associate the Linux login to a specific login name/pwd on the NAS?
My NAS is set up with multiple users/pwds with specific permissions to the directories on the NAS. So when I log in on my desktop, I want it to mount the NAS using one set of unames and pwds, when my wife logs in, I want it to mount the NAS using another set of unames and pwds.
Thanks, your article helped me understand NAS mounting.
February 28th, 2008 at 4:25 pm
@Shaan
Just create a symlink to the folder you mount the drive, like this:
ln -s /path/to/share /home/user/link_name
Then, your drive is safely mounted in /media, but you have a quick link to it in your home folder. Not sure if it will show up in the menu or not, I don’t use a desktop environment.
March 3rd, 2008 at 9:12 am
Tommasino:
I am using smb sharing on my windows server right now and it works with cifs. You can use smbfs if you install it first I believe, but I have never tested it with anything but cifs.
Blah:
I didn’t get the error you were experiencing, but I did start getting an error after logging in that had something to do with gnome settings manager not starting. If I waited a few minutes after booting my computer to log in I wouldn’t get this error. I think what was happening was the mount was taking a long time and it was holding up the other services from starting. I think someone else mentioned this might be an issue, but I never looked into a fix for it.
Root Kid:
I don’t think the configuration I have outlined here will work in your scenario. You need to look into using login scripts to mount shares. If you look in my previous post on this subject I use a script that runs when you log in as opposed to using the fstab file. You can see those instructions here. Basically you want to create a different .smbcredentials file for each of your users and make the .mountshares.sh script run when you log into linux. Make sure you ignore the last few steps where I add .mountshares.sh to the init process. You want it to run at login not boot.