Samba is the standard Windows interoperability suite of programs for the Unix-based operating systems. It allows network administrators for file and print sharing between the computers running Microsoft Windows and Unix/Linux systems. Basically, Samba uses SMB/CIFS protocol for secure, stable, and file/printer sharing including multiple other protocols like NetBIOS over TCP/IP (NBT).

Advertisement

Samba sharing allows multiple systems to share single resources over a network, like sharing a printer reduces hardware cost. Also, share the directory server using samba and mount it on remote systems easily.

This tutorial will help you to mount remote samba share to Ubuntu, Debian, or Linux Mint systems.

Steps to Mount Samba Share on Ubuntu and Debian

This tutorial assumes that you have already shared a directory on the remote system. Now, we will mount that shared directory to our Ubuntu or Debian system.

Follow the step-by-step guide for the mounting of remote samba share on the Ubuntu and Debian systems. Also enables to automount shared drive even after system reboot.

  • Step 1 – You need to install package cifs-utils on your system. Run the following command on the terminal for the installation.
    sudo apt install cifs-utils 
    
  • Step 2 – After that create a directory to mount the share drive.
    sudo mkdir /media/share 
    
  • Step 3 – Now create a credentials file to your system. Make this as a hidden file using dot (.) for security purposes. It’s good to create it in your home directory.
    nano /root/.smbcredentials 
    

    Set the samba username and password to the above file.

    username=smb_username
    password=smb_password
    
  • Save your file and make it readable for the root account only. This will restrict access to all non-root accounts.

chmod 400 /root/.smbcredentials 
  • Step 4 – Use the following command to mount remote samba share on a Linux system.
    sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.smbcredentials //192.168.1.10/share /media/share 
    

    But the manually mounted file system will not remain mounted after a system reboot. To mount samba share automatically after a system reboot, complete the next step.

  • Step 5 –You can make add the configuration to /etc/fstab file to auto mount remote share on system boot.

    Edit the below configuration file in your favorite text editor:

    sudo nano /etc/fstab 
    

    Add the line at end of the file as follows. Change values as per yours.

    //192.168.1.10/share /media/share cifs vers=3.0,credentials=/root/.smbcredentials
    

    Save file and close it.

  • Conclusion

    In this tutorial, you have learned to mount remote samba share on a Unix-like system. Also enabled to mount a remote share on system boot.

    Share.

    14 Comments

    1. The line you have to enter into /etc/fstab has a typo. Instead of

      //192.168.1.10/share /media/share cifs vers=3.0,credentials=/.smbcredentials

      It should be

      //192.168.1.10/share /media/share cifs vers=3.0,credentials=/root/.smbcredentials

      Or else it won’t follow the steps earlier in the tutorial and it will result in an error (and not mounting) at boot.

    2. Couple of things
      1. After editing your fstab file, ensure you run systemctl daemon-reload
      2. If your remote network share contains spaces, replace them with \040
      3. As of Debian 11, you need to do a couple extra things to get it to mount properly on boot
      – Append “auto” onto the end of your fstab options. (vers=3.0,credentials=/.smbcredentials,auto)
      – Check that the systemd-networkd-wait-online service is running, and if not, enable it (systemctl status systemd-networkd-wait-online) (systemctl enable systemd-networkd-wait-online)

    3. Hi, It will always mount as root user. Any solution for non-root user mount?

      The shared folder on the file server is granted 777 permission and owned by the non-root user.

      sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.smbcredentials //my.smb.com/test-shared/ /home/jk/testshare2/
      Thanks, JK

      • @JK
        hi,
        you have to add the mount option noperm, in your example:
        sudo mount -t cifs -o rw,vers=3.0,credentials=/root/.smbcredentials,noperm //my.smb.com/test-shared/ /home/jk/testshare2/

    4. Ludovic Kuty on

      Note that the option “vers=2.0” (or another version number) might be mandatory to choose the right protocol version to match the one of the server.

    5. Krishnakumar Masimalai on

      @ANDY D

      I too faced the same problem.

      Solution found is,

      sudo nano /.smbcredentials

      username=machine
      password=machine

      Save

      sudo nano /etc/fstab

      Add following line:

      //192.168.159.133/share_host/ /share_mount/ cifs vers=3.0,credentials=/.smbcredentials

      Save & Reboot

    6. I haven’t tried this, but surely there’s a typo in the instructions.
      He says: “sudo mkdir /media/Share” (with uppercase “S”)
      Later in the fstab example given, the directory is addressed as “…/media/share…” with lowercase “s”
      My understanding is that Liunx, unlike Windows, distinguishes between upper and lower case, in which case the address in the fstab example would fail to find the previously created address because of the case discrepancy.

    7. Guess they don’t teach how to secure a credential file at Red Hat Certified Engineer courses so it is not readable by everyone on the computer?

    8. Hi, I have tried following these instructions, but I am getting the following error:

      mount error(22): Invalid argument
      Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

      I am using gifs-utils version (2:6.8-1) running on Ubuntu 18.04.2 LTS.

      Can you please advise on what I am doing wrong?

    Leave A Reply

    Exit mobile version