Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Mounting Samba (CIFS) Share

I started working at an organization that uses a Windows Samba share to share temporary files over the network. To mount such a share, you need to mount a cifs type like below:

USERNAME="programster"
PASSWORD="putYourPasswordHere"
UID=1000
GID=$UID
SAMBA_SERVER_IP="192.168.1.2"
NAME_OF_SHARE="projects"
MOUNT_PATH="/mnt/projects"

sudo mount -t cifs \
  -o username=$USERNAME,password=$PASSWORD,uid=$UID,gid=$GID \
  //$SAMBA_SERVER_IP/$NAME_OF_SHRE \
  $MOUNT_PATH

The $NAME_OF_SHARE might not be the same as the name of the folder on the server that is acting as the share. This will often be the cause of a lot of pain. The name is whatever is specified in your Samba config file, or the "name of share" when selecting "share this folder" in windows.

Read-Only Access Issue - Specify UID/GID

When I first looked into performing the mounting, I didn't specify the uid or gid parameters and only had read access (no write). After specifying the UID and GID of my user on my local machine

To find out your user ID, just run:

echo $UID

If you want to find the ID of another user, use:

id -u $USERNAME

References

Last updated: 19th December 2018
First published: 17th October 2018