Want to be able to have an Ubuntu machine permanently mount a shared folder from a Windows machine n your network? Here’s how. As usual, this may not be the best way to do it, but it certainly worked for me.

We’re going to have to assume a few things:

  • Shared folder is already setup on the Windows box. The Windows version is probably not important here, as long as it is Windows 200o or better, including XP, Vista (ugh!) or Windows 7.
  • Permissions are set to allow a specific user to connect to the Windows share.
  • You have administrative (sudo) access on the Ubuntu box. This tutorial is based on Ubuntu 9.04 (Jaunty Jackalope) but probably works with 9.10 (Karmic Koala), 10.04 (Lucid Lynx), 10.10 (Maverick Meerkat), etc.
  • You know what sudo is and how to use it.

The Ubuntu machine is going to need cifs, and that comes along with smbfs. So, install smbfs by entering:

sudo apt-get install smbfs

Follow the direction to install smbfs if needed. This is what it will look like if it is already installed:

Reading package lists... Done
Building dependency tree
Reading state information... Done
smbfs is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.

Now, you need to create a folder on the Ubuntu machine that will be used to ‘house’ the mounted share. For this example, we’re going to create it on the Desktop for the user bigtone. Edit the path as your needs dictate:

sudo mkdir /home/bigtone/Desktop/shared_files

Next, we’re going to create a file for storing the Windows share login credentials. It is done this way so that the credentials can be protected from the average user snooping around. (Note that anyone that has ‘root’ privileges on the Ubuntu box can see this info. If that is a problem, don’t store the super secret key codes to the nukes this way. )

sudo vi /root/.smbcredentials

In the .smbcredentials file, add the following two lines, using your credentials for username and password:

username=bigtone
password=supersecretpassword

Note that if your share credentials are Windows Active Directory based, you can try the following method:

username=bigtone@BigToneDomain
password=supersecretpassword

…or, for cifs on Windows Server 2003 and higher:

username=BigToneDomain/bigtone
password=supersecretpassword

Now, secure the .smbcredentials file from prying eyes by making ‘root’ the file owner and locking the file so that only the file owner can see the contents of the file:

sudo chown root /root/.smbcredentials
sudo chmod 600 /root/.smbcredentials

# Edit fstab (make a backup first):

sudo cp /etc/fstab /etc/fstab_old
sudo vi /etc/fstab

# Add the following line to the bottom of fstab
# Replace UPPERCASE TEXT with applicable details
# Example:
# //COMPUTER_SHARENAME/SHARE_PATH /PATH/TO/MOUNT/DIRECTORY cifs credentials=/PATH/TO/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

//can-rip2010/gs3200_ripped /home/vutek01/Desktop/GS3200_Ripped cifs credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

# Mount the new share!

sudo mount -a

# NOTE: Will automatically mount in the future on boot / reboot