[Ubuntu Server] Permanently Mounting Samba Shares

Hey everyone, Although this isn't related to programming, it's still a tech post. I'm writing it mainly because I have forgotten how to do this more than once, had to research it, and I don't want to have to scour the web for the information again in the future.

So, let's get started.

  1. Log into your Ubuntu Server
  2. If you don't have cifs-utils already, let's get that installed.
    sudo apt-get install cifs-utils
    
  3. Create a new directory for the network server you're preparing to mount. I prefer to create them inside the /mnt/ folder. In my current case, the network drive that I'm mounting just has a lot of documents, so I'm going to create a folder: /mnt/documents.
    sudo mkdir /mnt/documents
    
  4. Change directory to /etc/, where your fstab file is located.
    cd /etc/
    
  5. Open fstab in an editor, like nano.
    sudo nano fstab
    
  6. Add the appropriate network map to the end of your fstab file. In my case, that will look like:

    //192.168.X.X/documents /mnt/documents cifs username=USERNAME,password=PASSWORD,iocharset=utf8
    
    • Replace 192.168.X.X/documents with your network location and share name.
    • Replace /mnt/documents with the folder you created in step #3.
    • Replace USERNAME and PASSWORD respectively.
  7. Write your changes to fstab from within Nano and exit the program.

  8. Check your work by running:
    sudo mount -a
    
    If you received no errors, then the network drive should have mapped properly and will automatically mount again each time your server starts.

Thanks for reading! I hope this helped!

Feel free to follow me on Twitter!