Back to TIL
shell

Mount a Samba Network Share

Automatic mounting of an SMB network share is well-supported.

  1. Make sure to have cifs installed: apt install cifs-utils.

    Otherwise, you might see error code -13.

  2. Open up your /etc/fstab and configure the mount point:

    //theip/sharedfolder /media/sharedfolder cifs credentials=/root/cifs-credentials,uid=1000,gid=1000,rw 0 0

    Dissecting this further:

    1. //theip/sharedfolder: Local Network IP of the computer sharing something.
    2. /media/sharedfolder: Where you want the folder mounted on your machine. We’ll create this shortly.
    3. cifs: the filesystem type.
    4. credentials=/root/cifs-credentials,: I assume the shared folder is password protected. We’ll store it in a separate file instead of the world readable fstab. Security! We get to this in a minute.
    5. uid=1000,: Specify the owner your local folder belongs to.
    6. gid=1000,: Specify the group owning your local folder.
    7. rw: read-write
    8. 0: don’t ever dump this filesystem. Doesn’t make sense with a network share.
    9. 0: don’t run fsck on this. Doesn’t make sense with a network share.
  3. Persist the credentials. Create the /root/cifs-credentials file and fill it up:

    username=shareuser
    password=sharepassw0rd
  4. Set permissions so that only root can read the file:

    chmod 600 /root/cifs-credentials
  5. Ensure the local folder exists:

    mkdir -p /media/sharedfolder

That’s that. Run mount -a to test. Once that worked, do a reboot and verify it actually works.