How To Map A Network Drive Onto Ubuntu 14.04 Permanently

August 11, 2014 — 51 Comments

Map Network Drive

This simple tutorial shows you how to map a network drive, Windows share as example, onto Ubuntu 14.04 LTS with read and write permission permanently.

All things will be done in a terminal window. Not familiar with Linux command? Don’t be afraid, just paste the command into terminal and hit enter to run one by one. There will be a few pictures to make things more clear.

Preparation:

There are a few preliminary actions we need to do before we can start mounting using cifs.

1. Press Ctrl+Alt+T on keyboard to open the terminal. Paste the command below and run to create a mount point, you can replace ‘Ji-share’ to what you want.

sudo mkdir /media/Ji-share

Create a mount point for network share

2. Install cifs-utils, which provides support for cross-platform file sharing with Microsoft Windows, OS X and other Unix systems.

Install it from Ubuntu Software Center, or via below command:

sudo apt-get install cifs-utils

3. Edit the /etc/nsswitch.conf:

sudo gedit /etc/nsswitch.conf

Find the line looks like:

hosts: files mdns4_minimal [NOTFOUND=return] dns

change it into:

hosts: files mdns4_minimal [NOTFOUND=return] wins dns

Ubuntu resolve Windows Hostname

4. Run below command so that your Ubuntu can resolve Windows computer name on a DHCP network.

sudo apt-get install libnss-winbind winbind

Reboot Ubuntu, or restart your network.

Mount (map) network drive:

Now edit the fstab file to mount network share on start up.

1. Make a backup by running the command below:

sudo cp /etc/fstab /etc/fstab_old

If you need to restore your backup, run:

sudo mv /etc/fstab_old /etc/fstab

2. Create a credentials file via:

gedit ~/.smbcredentials

insert the username and password for accessing the remote share. Replace “Ji” & “741852963″ with yours and save the file.

username=Ji
password=741852963

create-credentials

3. Run command to get your gid and uid. Replace handbook with your user name.

id handbook

Get Ubuntu user id

4. Now edit the fstab by running the command:

sudo gedit /etc/fstab

Add below line (one line) to the end and save it. REPLACE WORDS IN RED!

//192.168.1.5/share /media/Ji-share cifs credentials=/home/handbook/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

Map Network Share in Ubuntu

Finally run sudo mount -a in terminal and you’ll get the network share mapped in Unity Launcher and Nautilus file browser:

Map network share Ubuntu 14.04

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on Google Plus or email to ubuntuhandbook1@gmail.com

51 responses to How To Map A Network Drive Onto Ubuntu 14.04 Permanently

  1. This is exactly what I needed! I was mapping those network drives in a way that did not give me permission to write, modify or delete my files. Thanks!

  2. This article, and your article “Ubuntu 14.04 LTS: File Sharing With Samba” are very helpful.

    Your image in paragraph 4. with the “REPLACE WORDS IN RED” left out a word to replace. “credentials/home/handbook/.smbcredentials”. “handbook” should be your userid.

    The root problem in my case, though was with the VirtualBox VM. For some reason it gave my VM’s a fixed IP address at 192.168.56.x, where the rest of my LAN was DHCP from my router at a different subnet. Annoyingly, before I figured that out, some pings would work, the Ubuntu VM would show up on the Win7 Network folder, and vice-versa, and ping would resolve the names, but fail. I eventually found the setting page for the host-only ethernet. You have to go to the VirtualBox Manager, click File (upper left)>preferences>Network>Host-only Network, click on the adapter and then the edit brush on the right of that panel. Enable the DHCP server check box.

    Of course, now that sharing works, Firefox access to the net does not. I’m doing this for a couple of on-line courses, for the programming test bed. If this were a production environment, I would be fired for this incoherence.

    Anyway go to the VirtualBox Manager, select your VM, click settings (2nd line from top of Manager Panel, and change the active network adapter from “internal network” to “bridged adapter”. Reboot the VM. Now all works, except the “mount-a” from your paragraph 4. won’t allow a click from Nautilus because of permissions. But I can at least get to my shares by “Browse Network”.

    So 3 days later I can print on my networked Dell 2150cdn (cups and Dell drivers not part of base Ubuntu), share folders with my VM and my Windows 7 Workgroup (sharing, Samba, cifs not part of VirtualBox or Ubuntu base), copy/paste from host to VM (not part of VirtualBox Base), and use the internet (part of the VirtualBox/Ubuntu base, but is easily broken).

    My environment:
    Win 7 pro SP1 updated 8/30/2014
    VirtualBox 4.3.12r93733
    Ubuntu 14.04 updated 8/30/2014

    Maybe there should be a PPA or some hefty scripts to do these very common activities? I would be willing to help with documenting and automating the Win7 Host and Ubuntu 14.04 VM environment.

    The shortcut keys (below URL, techdriven) are vital. The default 14.04 desktop allows you to auto hide the start bar, but doesn’t sense the mouse to unhide it. And just try assigning your USB mouse adapter (on the host) to the VM (no-don’t, really). The shortcuts can save you. If you haven’t accidentally disabled your keyboard or display, pressing and holding down the Win key will bring up the menu of shortcut keys.

    Many thanks to:
    http://www.binarytides.com/vbox-guest-additions-ubuntu-14-04/
    http://ubuntuhandbook.org/index.php/2014/05/ubuntu1404-file-sharing-samba/
    http://ubuntuhandbook.org/index.php/2014/08/map-network-drive-onto-ubuntu-14-04/
    http://rottenrei.be/posts/2014-07-19-dell-2150cdn-color-under-ubuntu-14-04/
    http://www.techdrivein.com/2011/04/31-useful-ubuntu-1104-unity.html

  3. Thanks! This worked great. BTW–this also works equally well on Linux Mint 17.

  4. This looks like a near perfect way to run network backups of steel devices from a central Ubuntu server. I simply need to get comfortable with storing Windows share credentials in a file on Ubuntu. It will surely require a separate, non-interactive userid that has no priv on any machines.

    Other thoughts include making a Windows mapped network drive to the Ubuntu partitions. This still allows me to run Ubuntu-centric backups that catch the Windows boxes, but requires either Windows backups to the mapped drive or automated batch files running xcopy to the mapped drives. Additional complexity is rarely good.

    Virtual devices of any OS will of course run on the Ubuntu and be easily backed up.

    Thank you.

  5. How do you prevent failed mounts caused by spinup delays? If i reboot my ubuntu server while my unraid disks are spun down it fails to mount. I have to manually run sudo mount -a afterwards to get them back.

  6. Thanks.
    I’ve been struggling for a while to solve this issue, so it was great to find a post that gave such clear instructions.
    Works on Mint 17 Cinnamon accessing shares on a Synology DS213j server.

  7. Thanks !!!!!
    Ok to mount NAS server’s shares on my Ubuntu 14.10
    No, it’s not an utopia.
    :D

  8. Still no luck mounting my readySHARE. I keep getting the mount error(22): invalid argument message. Ehh, whatever, diving back into google.

  9. anyone please help!!! I tried mounting the network drive. I think everything worked till the last step, where it is asked to mount the drive using the command sudo mount -a. but on doing that, i get an error message like this.

    mount error(13): Permission denied
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

    I am very new to using ubuntu and I really need help in this!!!

    thanks

    • Try adding below line into the /etc/fstab file, adds sec=ntlm, username and password.

      //servername/sharename  /media/mountpoint  cifs username=msusername,password=mspassword,iocharset=utf8,sec=ntlm  0  0

      Take a look at this:

      http://unix.stackexchange.com/questions/124342/mount-error-13-permission-denied

      http://askubuntu.com/questions/313515/unable-to-mount-cifs-share-from-etc-fstab

    • I had the same issue and adding “sec=ntlm” did the right thing.
      This is the complete line added to the fstab file (of course it contains my own server details, so you need to adapt it to your):

      //192.168.0.1/Data /media/ceres/Data cifs sec=ntlm,credentials=/home/ceres/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

      If it does’t work try other security options:
      sec=
      Security mode. Allowed values are:
      · none – attempt to connection as a null user (no name)
      · krb5 – Use Kerberos version 5 authentication
      · krb5i – Use Kerberos authentication and forcibly enable packet
      signing
      · ntlm – Use NTLM password hashing
      · ntlmi – Use NTLM password hashing and force packet signing
      · ntlmv2 – Use NTLMv2 password hashing
      · ntlmv2i – Use NTLMv2 password hashing and force packet signing
      · ntlmssp – Use NTLMv2 password hashing encapsulated in Raw NTLMSSP
      message
      · ntlmsspi – Use NTLMv2 password hashing encapsulated in Raw
      NTLMSSP message, and force packet signing

      • Hi,

        I already use every recommendation posted here and on the suggested webpages for mounting a hdd on the working net. I’m using ubuntu 14.04. However, it seems noting is working, it’s still appearing mount error (115). I even try to solve it, but I really don’t know what’s happening. Please, can somebody help me?

        thanks :)

  10. Very nice guide, however when ending by mounting I get this

    salle@TopGun:~$ sudo mount -a
    [sudo] password for salle:
    Password for root@//10.11.12.5/backup:
    mount error(13): Permission denied
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
    mount: mount point 0 does not exist

    The post about adding the credentials to fstab did not work, the same output occours.

    Thx in advance.

  11. Hello. Thanks for your help but when I run:

    sudo mount -a

    in the terminal I get this reply:

    Unable to find suitable address

    Thanks!

    Paul

  12. This worked perfectly until a few days ago. Suspect some behind the scenes “update” screwed things up. All modification to files per your instructions are still there, but the thing just doesn’t mount, at startup, or with the mount -a command. Any ideas?

  13. Excellent! Thanks!

  14. When I run

    sudo mount -a

    in the terminal I get this reply:

    Unable to find suitable address

  15. A week or two ago I installed a Canan MX890 successfully on my first Ubuntu sytem (14.04). I am now trying to install the same printer on another Ubuntu 14.04 system and have been getting the following error:

    Failed to fetch ‘http://ppa.launchpad.net/michael-gruz/canon-stable/ubuntu/dists/trusty/main/binary-i386/Packages’ 404 Not Found.

    Is your repository down or could this error be my fault? I’m very new to Ubuntu and wouldn’t know how to troubleshoot this myself.

    Thanks,
    Min

  16. how to give certain letter like”h” to this mount

  17. Just gonna wade in for those of you with spaces in the share you’re trying to mount.

    In my case a Seagate NAS box labeled ‘Goflex Home Public’…
    i had to use 40 in place of the spaces…

    So…
    Goflex40Home40Public

    40 is a space in fstab

    :)

    • I had to use 40…

      GoFlex40Home40Public

      //192.168.1.12/GoFlex40Home40Backup /media/nas cifs credentials=/home/gary/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

      • The post didn’t keep exactly the syntax I used.

        Let me try to show it between quotation marks…

        Use ’40′

        Like this: GoFlex’40′Home’40′Backup (except you must remove the quotes when you add this to your /etc/fstab file.

        I wanted to share this with others, because I have been looking for this solution for two years!! Thank you so much for this post.

  18. Hi,
    I wonder what is the output of ls -al on any of your CIFS shares mounted like above? On my NAS share mounted like this:
    //srv/share /mnt/share cifs credentials=/root/.smbcredentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

    the files and dirs are all root owned (even when I create them as a user) with all rwx bits set, so konsole shows something not very usefull. I wonder if there could be done something to better deal with perms etc on CIFS?

    Maybe NFS is more friendly?

  19. Ji m: This article solved Ubuntu issues I have been struggling with for months. I just mapped a Windows machine and two network/modem drives. Thank you very much!!!

  20. This was enormously helpful, and incredibly simple; many prior attempts had failed. Thank you!

  21. Hi, thanks for the infos, sec=ntlm helped me a bit further. But I’m sticking with the permissions, too. I can’t modify data on the server. With former Versions of Ubuntu, I used uid= and gid=, but this doesn’t seem to work anymore. How do I set a uid/gid for propper permissions on the NAS??

  22. thanks, this worked beautifully.. the last time I mapped a network drive in Ubuntu 12 it took me several days to figure it out.. you made it much faster, thank you ;-)

    I did get the ‘Unable to find suitable address’ error, in my case it was because the IP address of the network drive had changed since the last time I tried it. Correcting that fixed the error.

  23. Another thing that I’ve found useful is adding the -v (verbose) switch to the mount command in the last step to get a bit more information when it isn’t working quite right. I was finding that mount appeared to have run, but was actually saying that the location was already mounted so it wasn’t actually applying any changes I had made to my fstab file. (I had it mounting read-only and I was making changes to fstab but nothing worked because it actually wasn’t being re-applied!)

  24. Thank you so much…I work with digikam doing lots of photo management and my photo library is on my blackarmour seagate NAS 220 attached to my router and everytime I want to open digikam I have to navigate to the NAS and mount it. But now digikam thinks it’s a local library and it find it everytime. Thank you so much

  25. If I wanted to add a second mounted smb, would I have to do the entire process over? or could I just add a second line to the fstab file?

  26. deplorable guide because of insufficient prerequisites stipulated

  27. Hi, Thanks.
    Works fine on LinuxMint 17.1.
    Perfect well explained.

  28. Thanks works great!! Only isn’t it insecure to place your password in a txt file?

    • #Danny

      that’s exactly what I was thinking…
      I stopped right after I saw instruction to enter my cred in that file…

    • instead of “credentials=/home/handbook/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0″ i just did “guest 0 0″ since my shared drive is on a private network, so the shared drive doesnt need credentials. if you use “guest 0 0″ you dont need to create the credential txt file.

  29. Really well written and just what I was looking for. Thanks for all your efforts.

  30. Works brilliantly – thanks so much for the clear instructions

  31. Hi,

    I tried your instructions to map network drive unto ubuntu 14.04. Unfortunately, after executing the command sudo mount -a, I am getting the following error message:

    mount error(115): Operation now in progress
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

    Can you please help me in this regard,

  32. THis worked great on both the windows desktop with in a VM and a VM running on my MAC Book as long as i used the 32 bit version of Ubuntu. If i used the 64 bit the instructions fail because of the way that it wants you to initialize cifs. I kept getting an error and was directed to read the mount.cifs man page.

    I am sorry and did not note the exact error and I have removed the 64 bit version.

  33. Good Article.. Say if we want to auto mount network map drive only in particular user login then what to do?

  34. Hi – I do have a recurring error that baffles me, but I want to start off by saying that this is a great article, clear and easy to follow after grinding through days of googling into many “newbie unfriendly” articles ahead of yours.

    The error is “error(6) no such device or address” refer to the mount cifs(8) manual page”

    Can’t make sense of anything about it on google searches.

    My systems: ubuntu server 14.04.3 headless, Windows 8.1 Pro (legit) – trying to map over a network drive to be able to send folder backups via DirSyncPro

    I did have to sort out the directories for the .credentials file prior to this error, as my user is root, but it is located now, and I can’t help but wonder if the problem originates back at the server address – is there something about “share” I’m not cluing in on?

    //192.168.1.58/share /media/Windows-Backups/RHD cifs credentials=/root/[myusername]/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

    All of the upper/lower cases are appropriate in my folder and names. Its all one line.

  35. Fixed the device issue, but hours of checking and adjusting the dirs and uid gid etc etc, and making sure its windows ip, I just can’t get past the “permissions” file permissions are now “owner rw” (0600)

    Like the article otherwise

  36. Thanks so much for the tutorial. I got this working for one drive..how would you go about doing this for two or more?

  37. Thanks for great tutorial. I have the error
    Retrying with upper case share name
    mount error(6): No such device or address
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

    I have tried all the hints suggested and have tried :smbclient -L //bananapipro -U pi
    where I received this
    Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.17-Debian]

    Sharename Type Comment
    ——— —- ——-
    IPC$ IPC IPC Service (bananapipro server)
    pserver2 Disk storage
    PISERVER Disk storage
    Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.17-Debian]

    My fstab is this
    //192.168.0.36/bananapipro /media/PSERVER cifs credentials=/home/ben/.smbcredentials,iocharset=utf8,sec=ntlm,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0

    Sorry for the bother

  38. Hi Ji,

    A nice and clear tutorial. Thanks. I was looking forward to having a permanently mapped network partition. For some bizarre reason I am seeing the message when attempting to mount the share:

    Unable to access “Steven-share”

    [mntent]: line 14 in /etc/fstab is bad
    mount: can’t find /media/Steven-share in /etc/fstab or /etc/mtab

    even though the directory ‘Steven-share’ is clearly created and accessible at /media.

    It makes no sense to me. I wonder if you have any thoughts?

    • Hi Ji,

      I managed to identify one of the issues. Now I see the following message when trying to mount the partition:
      Unable to access “Steven-share”
      mount: only root can mount //192.168.xxx.xx/Private_Steven on /media/Steven-share

      Any thoughts?

  39. THANK YOU!!
    :D
    I’ve successfully mounted NSA310s without any problems.
    Great tutorial !!

  40. Thank you so much for this article. Exactly what I needed and worked perfectly. Must admit that I don’t understand all of the commands, but happy to have the step-by-step instructions. Screen shots really helped see the exact text. Works great with Mint!

Leave a Reply

*

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>