How to permanently map a network drive

ubuntuThis article assumes that you are on a network that has a shared drive that you'd like to gain access to. In this example the share is a Windows share.


Terminal

Start by opening a terminal session on your Ubuntu desktop and run the following command, to create a folder in the /media directory.

sudo mkdir /media/MyNetworkShare

Next we will install cifs-utils, which allows us to interact with network shares from Windows, OSX and other Unix systems

sudo apt-get install cifs-utils

Now we can edit the /etc/nsswitch.conf file

sudo vi /etc/nsswitch.conf

In the nsswitch.conf file find the following line:

hosts: files mdns4_minimal [NOTFOUND=return] dns

...and change it to:

hosts: files mdns4_minimal [NOTFOUND=return] wins dns 

Install the following so that Ubuntu can resolve Windows computer names on DHCP network

sudo apt-get install libnss-winbind winbind

Restart your Ubuntu workstation.

Now we need to create a credentials file:

vi ~/.smbcredentials

Add the following lines, using a Windows user account that you're using to access the shared network drive.

username=steven
password=MyComplicatedPassword

Now run the following command to discover your Ubuntu user account gid and uid.

id steven

Now you can edit /etc/fstab

sudo vi /etc/fstab

...and add the following line, using the ip address of your file server and your gid and uid from the earlier step.

//192.168.12.34/share /media/MyNetworkShare cifs credentials=/home/steven/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

Finally you can run the following command to mount this share:

sudo mount -a

You should now see the mounted share in your Ubuntu desktop file manager.

 

Thanks for visiting.