Skip to main content

Ubuntu – Samba Client Setup and Persistent Shares

Posted on April 16, 2013 by TerryCoxTerryCox

Today’s topic is going to cover the Samba client setup and your ability to mount your Windows shares (Windows 8 included) on your Ubuntu desktop. Although you will get the basic information you need to install and configure your Ubuntu system for accessing Windows shares, if you want to see it in action (including those pieces on the Windows side) in more detail, please visit our sister site Linux Academy. There you can see not only how to configure your Ubuntu system for accessing Windows shares, but how to set up you Ubuntu server as a file server. Linux Academy offers a large number of certification level courses across a wide range of Linux topics. In addition to the demonstration videos, you have access to your very own dedicated Amazon Web Services Linux Server to follow along with each class!

Standing in One Place
The default setup for most home networks uses DHCP. The problem with DHCP is that it can make managing individual systems more difficult, particularly when you are not running and automatically updated internal DNS service (which most home users would not be doing). Make your life easier and set up your Ubuntu Desktop with a static IP address. This is done easily enough from your ‘Settings’ application, specifically the ‘Network’ settings which should look something like this:
You will notice in this particular case, that I have both a local DNS server for my network and a Windows domain. Neither of these are necessary for the purposes of sharing or mounting Samba shares, it just happens to be my configuration.
Laying the Foundation
Next step in our journey is to install install all the pieces for our Samba client. We are going to execute:
sudo apt-get install cifs-utils samba-common system-config-samba samba winbind
Strictly speaking, ONLY the ‘cifs-utils samba and samba-common’ packages are required since we are going to configure everything at the command line and ‘system-config-samba’ gives us a GUI management tool, we are including it here for flexibility later. Additionally, the ‘winbind’ package will help with full hostname resolution when viewing your local network.
System Prep
Time to edit our configuration file. Open a console and edit the ‘/etc/nsswitch.conf’ file and be sure the contents look like this:

passwd: compat
group: compat
shadow: compat
hosts: files mdns4_minimal [NOTFOUND=return] dns wins mdns4
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis

The only difference in this configuration versus the default install is the ‘wins’ parameter added in the middle of the ‘hosts:’ line. Be sure that exists, save your file and reboot your system.
Mount Up Partner
At this point, opening any of your file management software (Dolphin, Gnome Commander, etc) will now allow you to scan your network and view any Windows shares that have been made available and that you have credentials for (if you want to see this in action, again, please visit Linux Academy for a video that shows all of this in detail). However, we are going to take a known share and mount it manually.
First, let’s create a directory to attach our Windows share to:
sudo mkdir -p /mnt/tmpshare
…and now connect our share to that new directory:
sudo mount -t cifs //shareserver/sharename /mnt/tmpshare -o username=user
One of two things will happen now – (1) You will be prompted for a password so that the share will allow you access to mount it or (2) the mount command will simply succeed (if you do not have the share restricted by password). A simple ‘df -h’ command will check to see if the share now shows as locally mounted. At this point, let’s do a ‘sudo umount /mnt/tmpshare’ and get this ready to become a permanent share on our system.
A Permanent Commitment
So we have our mount location but we want that share to come up every time we reboot the desktop, and we do not want to have to type our password during every connection attempt (which would cause the reboot mount to fail), nor do we want to include our password for that share in plain text in the fstab file itself. First thing is to create a file in our home directory called ‘.smbcredentials’, which should look like this:


Follow that up with:
chmod 700 .smbcredentials
Finally, the ‘/etc/fstab’ file should look like this for our example:

# / was on /dev/sdb5 during installation
UUID=0d5cc054-7dbe-4799-83d8-e19160f748aa / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdc1 during installation
UUID=a76dc3a1-933c-4c08-9e4f-7563d447cdf2 /boot ext3 defaults 0 2
# swap was on /dev/sdb1 during installation
UUID=4769b8e1-196e-4a83-bc7f-7a6b2a28edc5 none swap sw 0 0
# our file share
//shareserver/sharename /mnt/tmpshare cifs credentials=/home/user/.smbcredentials,rw,noauto,user 0 0

Once we save that file, we can test that everything works as expected by executing:
sudo mount -a
Which will mount filesystems that are referred to in the ‘/etc/fstab’ configuration file that are not currently mounted. A quick ‘df -h’ will check the mount command succeeded.
Final Thoughts
Samba is a powerful client (and as you can see demonstrated at Linux Academy, a powerful Samba server as well) that allows you to easily and quickly share and edit files remotely. There are additional details that you may need, so visit our sister site or drop me a line and, as always, I will lend a hand where I can.


Image of Brian Dockwray
Brian Dockwray
4 years ago

I’m new to Linux Ubuntu and keen to learn but I’m a bit frustrated. I run a WD Mybooklive server on my Windows system mapped as drive Y.
In the Linux File Manager I can access the server and browse the contents. I can open pictures in the Linux viewer. The problem I have is with the Gimp and Audacity. I can’t access the server from either, to load or save work. Is there a work around this? I’d appreciate any advice. Thanks.

Image of Bob
3 years ago

Nice article, however; it did not work for me using 16.10 server. I changed the location of the .smbcredentials file to /etc/samba and applied chmod 0400 permissions to the file. Success!

Leave a Reply

Your email address will not be published. Required fields are marked *