Main Content

Mount A Network Share On Linux / Ubuntu

In this tutorial I will go over the steps need to mount a network share in Linux. The cifs-util suite is required in order to mount a network share, if the system you are working with lacks the suite this tutorial also covers the installation of the same. Like always the tutorial assumes you have root access or similar.

Create Mount Point

For every network share you wish to mount you need to specify a mount point just like we do with hard drives and USB drives. I would recommend creating the mount point in the /mnt directory.

mkdir /mnt/shares/share1

Install Cifs-util Suite

If the system you are working with lacks the cifs-util it can be installed using the package manager for your distribution.

Ubuntu and Debian users can use apt-get.

apt-get install cifs-utils

Scientific Linux and CentOS users can use yum.

yum install cifs-utils

Mount Network Share With Credentials

The basic command below will attempt to mount a network share with credentials, in this case the file server is a Windows Server 2003 and the client is a Ubuntu 12.04 server.

mount.cifs //192.168.1.107/share1/  /mnt/shares/share1/ -o user=user1,pass=user1password

Description:

  • mount.cifs – Mount using the CIFS
  • //192.168.1.107/share1/ – IP address or name of file server followed by the share name
  • /mnt/shares/share1/ – This is the mount point where our network share will reside
  • -o users=user1,password=user1 – This means options and in my case I am specifying the username and password to the share

Mount Public Share

To mount a public share or one that doesn’t require a password is even easier. All you are required to specify is the server IP address, share and mount point.

mount.cifs //192.168.1.107/share1/  /mnt/shares/share1/
  • mount.cifs – Mount using the CIFS
  • //192.168.1.107/share1/ – IP address or name of file server followed by share name
  • /mnt/shares/share1/ – This is the mount point where our network share will reside

Mount Share At Boot

Now that was easy, keep in mind that using the commands above will only result in the network shares being temporarily mounted, if the system were to be rebooted all mounted shares will be unmounted. If you would like to keep the network shares mounted even after a reboot you can acomplish this with the help of the fstab configuration file.

Add the following line to the bottom of your fstab configuration file. Modify to fit your needs.

//192.168.1.129/share1  /mnt/shares/share1  cifs  username=user1,password=user1password  0  0

Conclusion

Mount a network share in Linux doesn’t have to be a nightmare, as you saw above we are able to follow an organized process. I like it when there is minimal configuration files changes involved and the commands are easy to understand, as it was in the case for this tutorial.

Thank you for reading, if you have any input or comments use the comment section below.

Comments

  1. Commented on
    Comment by A-Friend

    Thanks a lot for your tutorial. I noticed one mistake: When you first mount with this command:
    [

    mount.cifs //192.168.1.107/share1/ /mnt/shares/share1/ -o users=user1,password=user1]

    you begin the authentication with “users=”. This needs to be “usersname=”
    For any other newbie that might struggle on that command.
    tx

    1. Commented on
      Comment by luisventura

      Thank you for taking the time to point out the error, it’s been fixed.

  2. Commented on
    Comment by Dan K

    Excellent guide. Works like a charm.

  3. Commented on
    Comment by The_Old_Crab

    Minor nit: in your fstab entry, “//192.168.1.129/share” should be ”
    //192.168.1.129/ share1″ in order to be consistent with your earlier example.

    1. Commented on
      Comment by luisventura

      Haaa!, you got me. Thanks for pointing out the error.

  4. Commented on
    Comment by LetsgovaGiants!

    Hey any way to hide the password?

    1. Commented on
      Comment by cmarek
    2. Commented on
      Comment by jkguy

      It will also ask for password if pass= is omitted

  5. Commented on
    Comment by supercore

    I followed all the instructions but I can’t write to the network share. I checked the permissions for /shares/share1/ and the owner and group are set to root.

    The owner and group for /shares/ is set the the main user.

    Is this normal? Is there any way to get read/write functionality or change the ownership of /shares/share1/ to the main user?

  6. Commented on
    Comment by supercore

    I figured out what the problem was. Adding in a “noperm” to the /etc/fstab/ made it work. I used the following example:

    //server/share /home/mountdirectory cifs username=smbusername,password=smbpassword,nocase,noperm,file_mode=0777,dir_mode=0777 0 0

  7. Commented on
    Comment by gk84

    its apt-get install cifs-utils

  8. Commented on
    Comment by 180181

    Worked like a charm. Many thanks

  9. Commented on
    Comment by Rick Robey

    Thank you VERY much. I have struggled with this needlessly, especially when I see how easy it really is. I especially appreciated the section about adding the shares to boot time.

  10. Commented on
    Comment by sae13

    it didint work for public folder

    #####

    sudo mount.cifs //192.168.1.13/public Mount/500g
    Password for root@//192.168.1.13/public:
    mount error(13): Permission denied
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

  11. Commented on
    Comment by Francesco Mantovani

    thank you

  12. Commented on
    Comment by usk78dk

    I was so happy when I found this. I’m really not any good to Linux, but had to set up a simple ‘server’, so thought I could do it with ubuntu, which had a user interface. But I have really struggled with getting my mounting to stay when rebooting, and for me it always seems like rocket science when reading different solution. So I thought this post was my savior. But when I reboot the computer the mounting hasn’t happened. I’m running ubuntu 16.04 LTS. I followed the guide above very carefully. The manual mounting is working, when I switch to the root user (sudo -i). Also after the changes are made, I can do the mounting manually, but it doesn’t happen on startup, and that is what I need. Don’t know what info I can provide you with, but really hope someone can help me. Would hate to have to run Windows on that server, but my Linux skills are just too limited to be able to do much other than following simple guides like this.

    1. Commented on
      Comment by usk78dk

      I have investigated some more. I found out that after reboot, if I run the command ‘sudo mount -a’ the mounting is happening. Read some place about someone had issues with auto-mounting after reboot as well and someone suggested it was because it happened before the network was available. They talked about adding ‘,_netdev’ after the password and this should delay the attempt to after the network was available. First I don’t know if adding the ‘,_netdev’ actually delays the command to after the network is available, but anyway, it didn’t help me.

Comments are closed.