Ubuntu Server – Mounting a Windows Share Using the Command Line

When I started writing this post I wanted to mount a Windows share in Ubuntu and backup files from Ubuntu  onto my Windows Home Server (WHS).

Since then I have begun looking at other options like TimeDicer and rdiff-backup – so I have not decided yet on which path I will take to backup /var/www directories and different MySQL databases.

Nevertheless I did succesfully get a share on my Windows Home Server (WHS) mounted, as follows.

First I chose to create a new user on WHS called vmbackup and this process created the vmbackup user share //WHS/Users/vmbackup.

Now on to the steps that we need to complete on Ubuntu Server.

I like to use nano to edit files on Ubuntu Server – and you can install nano as follows:

sudo apt-get update
sudo apt-get install nano

Because I want to backup to a Windows share I also need to install the Samba filesystem:

sudo apt-get install smbfs

The next step is to edit the /etc/hosts file and add a reference that points to my Windows PC:

sudo nano /etc/hosts

The IP address of my WHS is so I added the following line to my /etc/hosts file: whs

In nano press Ctrl + O and then Enter to save and then Ctrl + X to exit.

Now create a local directory that we will use to map our WHS share to:

sudo mkdir /mnt/whs-backup

To mount the Windows share we need to edit /etc/fstab with the path to the Windows share and the local mount point as follows:

sudo nano /etc/fstab

Add the following line to /etc/fstab:

//whs/users/vmbackup  /mnt/whs-backup  cifs exec,credentials=
/etc/cifspw,rw,uid=ubuntu-username 0 0

Note that the above line points to /etc/cifspw for credentials for mouting the Windows share. Also note that the uid refers to your Ubuntu Server username. If you do not include a uid and username then only the root user will have write permissions to the Windows share.

Create the /etc/cifspw file:

sudo nano /etc/cifspw

Enter your credentials to the Windows share:


Obviously you will need to specify your own username and password.

Secure /etc/cifspw as follows:

sudo chmod 600 /etc/cifspw

Mount the Windows share with the following command:

sudo mount -a

At this point reboot Ubuntu Server so that it can pick up permissions for the Windows share:

sudo reboot

Quickly check that you have write permissions as follows:

cd /mnt/whs-backup
touch text.txt

You should be able to create the test.txt file without any issues.

Hopefully this will help you is you are having issues mounting a Windows Share in Ubuntu.

Sources: industriousone and the Ubuntu Forum,


2 thoughts on “Ubuntu Server – Mounting a Windows Share Using the Command Line

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s