This snippet will show you how to add a Windows share to Ubuntu on boot.

Environment

  • Windows 10
  • Ubuntu 18.10

How to

  1. Share a folder in Windows 10 (we assume the IP address of this machine is 192.168.20.11 and the hidden share is named MyShare$).

  2. Install the CIFS utilities in Ubuntu:

    sudo apt install cifs-utils
    
  3. Add a samba credentials file under your home directory named .smbcredentials and assign the proper permissions:

    vim  ~/.smbcredentials
    chmod 0640 ~/.smbcredentials
    

    The content of the file should be in the format:

    username=<username [can be in the format [email protected]]>
    password=<password>
    domain=<domain [optional]>
    

    Note: The credentials are those of a user with share access set up in Windows.
    Note 2: If you are mounting the share "system wide" you could add the .smbcredentials file to the /root/ folder and assign the proper permissions as suggested here.

  4. Create a folder where the share will be mounted (in this case: /media/mySharedFolder) and assign it to your user.

    sudo mkdir /media/mySharedFolder
    sudo chown $USER: /media/mySharedFolder
    
  5. Edit the /etc/fstab file and add the mount point as follows:

    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    //192.168.20.11/MyShare$            /media/mySharedFolder  cifs    credentials=/home/<user>/.smbcredentials,uid=<user>,gid=<group>,iocharset=utf8       0   0
    

    Note: If you don't want to use a credentials file (not recommended) instead of writing credentials=<path> you can write username=<user>,password=<password>,domain=<domain>.

  6. Try to mount all defined entries:

    sudo mount -a
    

If everything went right, you will have your mounted share in /media/mySharedFolder.