Mounting a network drive in Linux (Ubuntu)

This is a very simple thing to do, it isn’t however as simple as one might think if you are coming from a Windows background, and are used to mapping a network drive from the Tools menu. As a note this is a guide for Ubuntu, although I have it working fine on both Ubuntu and Fedora, use the appropriate package manager/command line for Fed and the rest is the same.

First, we need to make sure that samba is installed:

sudo apt-get install smbfs

Next, we need to make a directory to mount the drive too. As an example, I’ve just reinstalled my Ubuntu (and Fedora) distribution, and so want to map the music drive on my server. I chose /media/ as the logical place to stick my network drives:

sudo mkdir /media/music

Next we need to tell the file system table where the drives are, and where to mount them. We also need to include our login credentials (will cover this later).

gksudo gedit /etc/fstab

Scroll to the bottom of the file and add the following:

#Mounting Network Drives
//SERVER/SHARE-NAME /MOUNT-POINT smbfs credentials=/credentials-file-location

To make the above make a bit more sense, here is my configuration:

//192.168.1.50/Music /media/music smbfs credentials=/home/russell/credentials.smbcredentials
//192.168.1.50/Videos /media/videos smbfs credentials=/home/russell/credentials.smbcredentials
//192.168.1.50/Software /media/software smbfs credentials=/home/russell/credentials.smbcredentials

What this will do is to check within the credentials file (more on this at the bottom) your username and password for your server (I am running a Windows Home Server as an example).

Next, we need to make the filesystem mount the drive, which we do simply with:

sudo mount -a

Finally, we need to make that credentials file. Simply navigate to your chosen directory (I stuck it in my /home/russell directory for ease), create a new file with the following information:

username=username
password=password

And save it with the same filename you gave the /fstab/. Thats it.

Leave a Reply