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.
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