Very frequently I need to mount SMB2 or SMB3 shares inside of my linux devices. To do so I usually use
You will need to install Samba and CIFS utilities
1 2 sudo apt update sudo apt install samba smbclient cifs-utils -y
The first thing to do is create a mounting point. This is a directory on the filesystem that will eventually become the share. It’s important to never put files in this directory as they will be overwritten when the share is eventually mounted. In this example I will be adding a backup share, so I will add the following directory:
1 2 cd /mnt/ mkdir backup
Then I’ll need to edit the
fstab file so that my share is mounted at boot.
1 sudo nano /etc/fstab
1 //<server>/<share> /mnt/backup cifs vers=3.0,credentials=/root/.mnt_backup_creds,uid=1000,gid=1000 0 0
Notice I do not specify the credentials in
fstab. Instead I designate a credentials file in the root directory. This is for an added layer of credential security.
1 sudo nano /root/.mnt_backup_creds
1 2 username=<username> password=<password>
Now the share should be ready for mounting. Use the
mount command to test the share.
1 mount /mnt/backup
I’d like to eventually explore using
systemd but that may be another post someday.