Auto-mount Samba Share on Ubuntu and Windows

SambaSamba is a very popular program used to share files, folders, and printers throughout networks with different computers and operating systems.  It's useful if you want to store or share things from one computer, say on an Ubuntu file server, and then access them from around the network, say on a Windows desktop or Ubuntu desktop.

One question I see a lot of mixed answers for on the Ubuntu Forums is "how can I auto-mount my samba share?"  So here are some quick and easy ways to get your samba share mounted on login.

Windows

Windows is pretty straight forward.  The first thing is to open up Notepad.  Paste in the following:

@Echo Off
net use M: \\192.168.1.10\myshare /USER:myusername mypassword

 

Replace M with the drive letter you want.  If you don't know what this is, just keep it M.  You will want to replace the \\192.168.1.10\myshare with the path to your samba share.  Also, replace myusername and mypassword with your samba username and password.

Save the file as "samba.bat" in your My Documents folder.  Be sure to use quotation marks in the file name, or your file will end up as samba.bat.txt which is not what we want!

Now go to Start > Programs and right-click on the folder called startup.  Click on New > Shortcut.  Simply browse over to your newly created samba.bat and you're done.  Now whenever you login to your Windows machine, your samba share will be mounted as the M:\ hard drive.  You can add more lines to your backup.bat, just be sure to change the M to another letter for each share.

Ubuntu

Ubuntu is slightly more complicated, but you can handle it ^.^.  The first thing is to open up your Text Editor.  Paste the following:

sudo -S echo "Connecting to samba share" -alt <<EOF
myubuntupassword
EOF
sudo smbmount //192.168.1.10/myshare /home/myusername/share -o username=myusername,password=mysambapassword
clear
echo "Connected!"

It's slightly more complex than the Windows version.  The reason is that you are required to use sudo in order to mount anything on the system, so we need to take that into account in our script.

Replace myubuntupassword with the password you use to run sudo (usually your login password.)  Replace //192.168.1.10/myshare to the path of the samba share.  Replace /home/myusername/share with the folder you want to mount the samba share as.  Also, replace myusername and mysambapassword with your samba username and password.

Save the file in your home folder as samba (add a period to the beginning, .samba, if you want to make it hidden.)  Now go to System > Preferences > Sessions.  Click the Add button, and name it Samba mount.  Then browse over to your home folder and select the samba file you created earlier (or .samba if you decided to make it hidden.)  Click OK and close the window.  Now, when you login to your Ubuntu system your samba share will be mounted as the folder you specified.

For both Windows and Ubuntu, you may want to put the startup file (samba.bat or samba/.samba) in a hidden folder or make the file hidden.  This will help keep your password hidden in case somebody uses your computer.

1 response to "Auto-mount Samba Share on Ubuntu and Windows"

1. The reason is that you are

The reason is that you are required to use sudo in order to mount anything on the system, so we need to take that into account in our script.
natural tinnitus cures | warts home remedies