Mount Network Share using fstab

  • Mount a network share to a folder on a Linux Server using cli.
    I’ve tested this on both Ubuntu or CentOS Operating Systems and the setup is basically the same.
  • First, install the required applications.

    sudo apt-get install samba-client samba-common cifs-utils
    sudo yum install samba-client samba-common cifs-utils

    It helps if some files are residing on the network share to verify this worked (even if it is just a simple test file).
    On the Linux Server Navigate and make a folder. For example, call it data.
    cd /usr
    mkdir data

    Next, create another folder and password file as root to protect who sees it:
    Let’s make a folder as root called info, then cd into info:
    cd /usr
    mkdir info
    cd info
    Let’s make a hidden file called .smb while in the info folder.
    Using . in front of smb file makes the file hidden-if needed use the command **ls -a** to view hidden files.
    Using text editor nano make the file as seen below, adding username and password in the following format.
    nano .smb
    domain=If Needed

  • To save and exit in Nano, from your keyboard press control+o to write the file, then control+x to exit.
    Next, edit the fstab file
    nano /etc/fstab
    Place the following at the bottom of this file and adjust accordingly. Then save and exit.
    //server IP/path/to/share /usr/data cifs credentials=/usr/info/.smb 0 0

    Test by running the command **mount -a** to verify the share mounted. Then reboot the server.
    If everything worked correctly, navigate to the /usr/data folder on Linux Server, and verify your network share is still mounted.