One of the reasons we always stuck to Windows was because all the other desktop computers in our network had Windows, and it was comfortable to share files inside the network through the “Homegroup” that Windows offers. We heard about SMB shares before, but we always thought it would be hard to configure – until we actually tried it.

In this guide we will setup a SMB / CIFS share between a Windows desktop computer and a Ubuntu Desktop laptop. We will also set secure permissions. Let’s begin!

EDIT 2015-12-20: Read this guide on how to make it mount automatically when the laptop boot into Ubuntu

  1. Share the folders you want on your Windows machine

    We have now created a share on the network with full access to a specific user.  Please remember to add a strong password to the user that gain full access.

  2. Make a folder structure on you Ubuntu machine.

    As we share several different folders, we obviously want these shares to be separated on our Ubuntu machine as well. To do this, we have to create different folders that will host the different shares. All the shares will be located in /media so we have to create sub-directories to /media.

    $~: sudo mkdir /media/share1

    We have now created “share1” on our Ubuntu machine.

  3. Add the share to fstab
    $~: sudo nano /etc/fstab

    We add the share to fstab to be able to mount it automatically when the Ubuntu machine is booted. Add this at the bottom of your fstab:

    // /media/share1 cifs credentials=/home/daniel/.smbcredentials,iocharset=utf8,uid=daniel,gid=daniel 0 0

    One of the most important things here are the “gid” and the “uid”. This is the user that will be able to connect to the share, in our case “daniel” on our Ubuntu machine. To make it more secure, we also don’t write out the username or password in clear text – we store it inside a file called “smbcredentials” that’s hidden.

  4. Create a password file
    $~: sudo nano /home/daniel/.smbcredentials

    Add this, and then save & exit:

    # Password for the Windows user
  5. Set 770 permissions to /media as the Ubuntu user you choose in “uid” and “gid”
    $~: chmod -R 770 /media
  6. Mount the smb share
    $~: mount -a
  7. And you’re all done! now that wasn’t so hard, was it?

Pro tip

Make Virtual Hosts in Apache.