Adding a Persistent Share to Ubuntu Linux

The main characters in this (pseudo) script are:

  • mountpoint–Typically something like /mnt/myshare or /media/myshare
  • username–The username used to access the share.
  • password–The password used to access the share.

Create the mount point if it doesn’t exist.

sudo mkdir [mountpoint]

Install CIFS support.

sudo apt-get install cifs-utils

edit the nsswitch.conf file.

sudo gedit /etc/nsswitch.conf

Find this line:

hosts: files mdns4_minimal [NOTFOUND=return] dns

and ensure it looks like:

hosts: files mdns4_minimal [NOTFOUND=return] wins dns

Install WINBIND.

sudo apt-get install libnss-winbind winbind

At this point, restart the network or reboot.

sudo systemctl restart networking  OR
sudo systemctl restart networking.service  OR
sudo reboot

Backup the original fstab.

sudo cp /etc/fstab /etc/fstab-orig

Create a Samba credentials file in your home directory.

gedit ~/.smbcredentials

This file should only contain the following:

username=[username]
password=[password]

Note: in the file above, the username is the name of the user used to access the share. It may be different from your Ubuntu username / login.

Get the user id from the command line.

id [username]

Note: in the command above, the username is your Ubuntu user name, i.e. your current login.

This will return something like:

uid=1000([username]) gid=1000([username])[]

The numeric “uid” and “gid” is what you’ll need.

Edit the fstab and add the new entry.

sudo gedit /etc/fstab

Add the new entry and save (should be one line).

//server/share [mountpoint] cifs
credentials=/home/[username]
/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,
file_mode=0777,dir_mode=0777 0 0

Make sure the “uid” and “gid” = values from above (here, 1000)

Re-mount file systems immediately or reboot.

sudo mount -a  OR
sudo reboot

© mylevel4cache.com, 2019. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to mylevel4cache.com with appropriate and specific direction to the original content.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s