Permanently Mount Network Share

Permanently Mount Network Share
Photo by Ningyu He / Unsplash

Original Post:

How do I permanently mount a windows network share in Ubuntu?
I’m trying to figure out how to permanently mount a windows network share in Ubuntu. Can anyone help me with the required steps?


The steps below have the mount points in the ‘/media/‘ folder, this follows what was recommended on some source webpages. When I started to solve this problem my mount points were setup in the ‘/mnt/‘ folder, as of now I am not sure if that will still work. You could give it a try if that’s what you want.

Sources:

MountWindowsSharesPermanently - Ubuntu Wiki
How to Automatically Mount Network Shares on Linux
A lot of tasks on Linux are complicated, especially when you have to do them manually. Mounting network shares is no different as you need to configure logins, input IP addresses, and more.Everything goes much smoother when you automatically mount network shares. You can do that inside the fstab file. Read on and you will […]
How to change permissions on mounted windows share?
I have mounted a windows share, But only root have write permissions.. I need to change that to my user so my programs can download and save stuff to my windows share. commands I’ve have used to…
Ubuntu Server 18.04.01 LTS CIFS Mount failing
Having issues getting my persistent network shares to mount in Ubuntu, here is what ive added to /etc/fstab //192.168.2.10/AlphaData_GlobalShare /media/AlphaData cifs credentials=/root/.

After new Ubuntu install, additional packages to add:

samba-common, samba, smbclient

Open ‘Terminal’ and enter the following commands:

Install cifs utilities

sudo apt-get install cifs-utils

Create mount points for windows shares and set permissions

sudo mkdir /media/mountName
sudo chown userId:userId /media/mountName
sudo chmod 755 /media/mountName

Create ‘credentials’ file to hold userid/password and set permissions

sudo nano ~/.smbcredentials

Enter the following 2 lines

username=windowsLoginId
password=windowsPassword

enter 'ctrl-x', then 'y' and finally 'enter' to exit and save file

Set permissions to hide username and password

sudo chmod 600 ~/.smbcredentials

Retrieve ‘uid’ and ‘gid’ values for next step

id

the ‘id’ command will output something similar to the following:

uid=1000(userId) gid=1000(userId) groups=1000(userId),4(adm),………….,1001(smbgroup)

Backup and edit ‘fstab’ to mount window share at ubuntu startup

mkdir ~/system-backups
cp /etc/fstab ~/system-backups
sudo nano /etc/fstab

at end of file enter the following line:

//winServerName/shareName /media/mountName cifs credentials=/home/userId/.smbcredentials,uid=1000,gid=1000,vers=3.0,nounix 0 0
💡
For the last 2 ‘0’ enter a ‘tab’ before the ‘0’ and delete any carriage returns.

If your share contains spaces, instead of the spaces, input:

\040

For example:

//winServerName/My\040Shared\040Drive

enter 'ctrl-x', then 'y' and finally 'enter' to exit and save file

Test mounting of windows network share

sudo mount -a

if no errors appear, the mount should appear in ‘file manager’

check mount in file manager for read/write access

Test permanent network share

shutdown and reboot pc

open ‘file manager’ and check network share

Other relevant commands

manually mount network share

sudo mount -t cifs -o username=windowsLoginId //winServerName/shareName /media/mountName

you will be prompted for the ‘password’

prepare mount point for deletion; do not run command where ‘pwd’ is ‘/media’

sudo umount /media/mountName

delete mount point

rmdir /media/mountName