Connecting to a NAS server from Windows, Linux and MacOS

In this short tutorial I will show you how you can connect to your local NAS server that's been configured with Samba from all major Desktop OS, Windows, Linux and MacOS.

Connecting from Windows

On windows, if you want to connect to a NAS server through the file explorer, follow this tutorial. Note that the folder you need to specify has the following structure.

\\192.168.178.98\first-nas-folder
  

If you followed the tutorial on how to set up a nas server then you will have noticed that the IP address is the private IP address of our NAS server and the directory name is the name we specified in the smb.conf. All that is left for you to do is to connect with your credentials.

Note that you must have your network as a private network. Otherwise you won't even be able to discover your local NAS server. More on this here.

Connecting from MacOS

Follow this tutorial to connect to a NAS server from MacOS. Note that you will have to write the following as the server address.

smb://192.168.178.98/first-nas-folder
  

If you followed the tutorial on how to set up a nas server then you will have noticed that the IP address is the private IP address of our NAS server and the directory name is the name we specified in the smb.conf. All that is left for you to do is to connect with your credentials.

Connecting from Linux

Connecting to your NAS server from Linux can be a little bit more tricky. If you want to use the file explorer then it highly depends on the desktop environment you are using. It should be similar to the Windows file explorer, but again, as there are so many desktop environments and even more file explorers it can vary quite heavily. I am going to show you an approach using the terminal. This will work on every linux distro, regardless of the desktop environment. It will even work if you don't have any desktop environment at all (on headless systems)!

Creating SSH Short Handle

In order to make our lives easier, let's create a hostname for our NAS private IP address. We do this by adding the following line to ~/.ssh/config.

Host server-name
  HostName 192.168.178.98
  User your-server-user
  

Replace the HostName with the private IP address of your NAS server and User with the username of your NAS server. Note that the private IP address here is the one of our NAS server. This should look familiar to you if you followed the tutorial on how to set up a nas server.

Connecting to the NAS server

Before we can actually set up the connection to the NAS server we first need to create a directory where the content of the NAS server should go into. We will also need to create a credentials file for fstab to use on boot.

mkdir ~/my-nas-folder
mkdir -p ~/.config/nas/
touch ~/.config/nas/credentials
  

Inside of the ~/.config/nas/credentials file, add the following content with your username and password of the samba account you created on your NAS server, NOT your credentials of the server itself.

username=samba-account-user
password=samba-account-password
  

Now we can add the following content to the /etc/fstab file.

//server-name/first-nas-folder /home/your-desktop-user/my-nas-folder cifs credentials=/home/your-desktop-user/.config/nas/credentials,uid=your-desktop-user,gid=your-desktop-user 0 0
  

Next make sure cifs package is installed.

sudo apt-get install cifs-utils
sudo systemctl daemon-reload
  

Now test to see if everything went well by running the following.

sudo mount -a
  

If you don't get any error messages, then you should see the contents of your NAS server in side of your ~/my-nas-folder. On every mount your machine will automatically connect to the NAS server. You should try it by rebooting your machine. Once you made sure this works, you are all done!