SMB File Share - How do I automount a share on user login?

How do I have a SMB File Share auto mount on user login with a username and password? I read something about fstab file but I really want to know more about it. What is it? How do I use it? What are the possible command variables?

Current System:

Ubuntu Gnome 17.04

SMB Server Location

smb:// HD/

I really would appreciate any help I can get on this, It's times like these that Linux frustrates me; It's so simple on Windows.

1 Like

make a text file that contains these two line:


where the username is the username for the SMB share and password is the password. For security you should change the permissions so the file is only readable by root, but it will work either way.

Then make a folder that you want to use as the mount point for the smb share, like /media/whatever

then add a line like this to /etc/fstab:

// /media/whatever cifs defaults,credentials=/path/to/cedentials/file,users,auto,uid=1000,gid=1000 0 0

where /path/to/credential/file is the path to the file you made with the username and password

then run these two commands:

sudo systemctl daemon-reload
sudo mount -a

after that it should work fine.

1 Like

Won't the auto mean the system will hang/kernel panic if the system happens to boot with no network access or when the share is down?

Autofs might be a slightly better option depending on your setup.

Not really, if it's not there at boot then at worst it will try for 90 seconds before giving up and moving on. If it becomes a problem you can just add the noauto option and run the mount command as a startup application.

1 Like