5

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

3
  • 1
    ask ubuntu is a Q&A site. I’m voting to close this because it's not a question.
    – graham
    May 31, 2021 at 17:14
  • @chicocr you should edit the question, and separate the question from answer. Then post your own answer, and accept it as an answer. Thanks.
    – Jags
    May 31, 2021 at 17:15
  • Does this answer your question? How to change permissions on mounted windows share?
    – karel
    Jun 3, 2021 at 8:42

1 Answer 1

9

I spent countless hours and visited numerous webpages to what I thought would be a straight forward problem. After writing up my notes for future reference, I decided to post them here to help anyone who might have similar problems. The notes have gone thru a few revisions and for reference there are 4 sources for further reading.

This solution has been installed and working on three ubuntu VM’s that are running under Windows 10 Pro Hyper-V and Ubuntu 20.04 KVM VMM. So far the network shares popup quickly and there is no appreciable lag times when traveling up and down the directory trees.

This solution solves a similar problem in Hyper-V when using ‘passthrough hard drives’; the Ubuntu vm's have only ‘read’ permissions on the hard drives. Unfortunately, Microsoft discourages using passthrough hard drives and this caused me to look for a linux solution. The hard drives are needed since they are to be used for extensive i/o. In my experience hard drives have faster write speeds and usually last longer than ssd drives.

Installation Notes:

  1. 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.

  2. xrdp, which enables remote desktop access to a ubuntu-pc, was used in all my installations. If you do not need this capability omit this package from the first step; everything else should still work.

  3. All the steps listed are what I actually used.

——————————————————————————————————————————

Source: https://wiki.ubuntu.com/MountWindowsSharesPermanently

Source: https://www.techjunkie.com/automatically-mount-network-shares-linux/

Source: How to change permissions on mounted windows share?

Source: Ubuntu Server 18.04.01 LTS CIFS Mount failing ——————————————————————————————————————————

after new Ubuntu install, additional packages to add:

xrdp, 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

(Note: for the last 2 ‘0’ enter a ‘tab’ before the ‘0’ and delete any carriage returns)

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
6
  • 1
    I do this all the time. What's xrdp for? It seems unnecessary, at least I don't have it installed. Also cifs-utils pulls in samba, so if you install it first, you save a step. May 31, 2021 at 21:24
  • 1) In my research I came across a lot of answers but none worked for me; my solution was put together from various articles. 2) I am using xrdp for 'remote desktop' access. I have multiple pc's (windows, mac's and ubuntu) and vm's on my home network and I can login to all these machines from my main desktop pc. 3) Thanks for the tip on cifs-utils.
    – ChicoCR
    May 31, 2021 at 22:06
  • 2
    Good info, but xrdp has nothing to do with mounting shares with samba, so it doesn't belong in these instructions AFAIK May 31, 2021 at 22:22
  • @chicocr since the question and answer both belongs to you, and the answer working for you, you should "accept" the answer by clicking little tick right underneath "vote arrows". Thanks.
    – Jags
    Jun 1, 2021 at 19:52
  • I was able to use this successfully on Ubunut 20.04 LTS - However //WinServerName/shareName did not work. I was able to use //192.168.x.x/shareName instead (static local IP).
    – Tank
    Mar 6, 2022 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .