I recently invested in a NAS device to add a little bit of redundancy to my personal files. With this particular NAS the most convenient way to use the files it stores is via the Windows share protocol (also known a SMB or CIFS). Linux has supported these protocols for a while now so that’s great but I wanted it to automatically map the shared directory on the NAS to a directory on my Linux computer on startup. Thankfully there is a very easy way to do just that.
1) First install cifs-utils
sudo apt-get install cifs-utils
2) Next edit the fstab file and add the share(s)
To do this you’ll need to add a new line to the end of the file. You can easily open the file using nano in the terminal by running the command:
sudo nano /etc/fstab
Then use the arrow keys to scroll all the way to the bottom and add the share in the following format:
//<path to server>/<share name>    <path to local directory>    cifs    guest,uid=<user id to mount files as>,iocharset=utf8    0    0
Breaking it down a little bit:
- <path to server>: This is the network name or IP address of the computer hosting the share (in my case the NAS). For example it could be something like “192.168.1.1” or something like “MyNas”
- <share name>: This is the name of the share on that computer. For example I set up my NAS to share different directories one of which was called “Files”
- <path to local directory>: This is where you want the remote files to appear locally. For example if you want them to appear in a folder under /media you could do something like “/media/NAS”. Just make sure that the directory exists (create it if you need to).
- <user id to mount files as>: This defines the permissions to give the files. On Ubuntu the first user you create is usually give uid 1000 so you could put “1000” here. To find out the uid of any random user use the command “id <user>” without quotes.
So for example my added line in fstab was
//192.168.3.25/Files    /media/NAS    cifs    guest,uid=1000,iocharset=utf8    0    0
Then save the file “Ctrl+O” and then Enter in nano.
3) Mount the remote share
Run this command to test the share:
sudo mount -a
If that works you should see the files appear in your local directory path. When you restart the computer it will also attempt to connect to the share and place the files in that location as well. Keep in mind that anything you do to the files there also changes them on the share!
BS”D
Thanks for this article! We’re having an issue where a Windows 7 Pro shared folder is accessible by Ubuntu 14.04 computers only part of the time. Nearly everyday it’s necessary to restart the Win7 machine as well as the Ubuntu machines to renew access to the shared folder. Perhaps your steps will alleviate this issue. Thank you!
BSâ€D
Thanks for this article! We’re having an issue where a Windows 7 Pro shared folder is accessible by Ubuntu 14.04 computers only part of the time. Nearly everyday it’s necessary to restart the Win7 machine as well as the Ubuntu machines to renew access to the shared folder. Perhaps your steps will alleviate this issue. Thank you!