0
0
0
s2sdefault

One of the wonderful things about Linux is that you can mount folders hosted on remote servers, and use and access them just like they were local folders. While there are a bunch of different protocols to access those remote folders, by far one of the most common is SMB/CIFS (Server Message Block (SMB), one version of which was also known as Common Internet File System (CIFS) ). In this article, we will go over mounting a password protected SMBV/CIFS share, not just once you've got things going, but automatically at boot time.

To start things off, we are going to assume that you already have an SMB/CIFS share out there somewhere. While entirely possible to have this shared over the internet, I would NOT suggest sharing over the internet, or your WAN, unless you KNOW EXACTLY what you are doing. We are also assuming that the SMB/CIFS Share is password protected. If yours is not, I would suggest you carefully review what, why, and how you are doing this.

Let us next clarify a couple terms we will use here. Technically speaking, just about *ANY* device can operate as the "server", and some hardware servers can (and do) connect as a "client". So,:

Client: This is the PC we will be mounting the SMB/CIFS Share on

Note: The Client CAN be a Checkpoint device running Gaia (*NOT* Embedded Gaia like the 1100s)

Server: This is the device that is hosting the SMB/CIFS Share

Going forward, all the commands and work we will do will be on the Client PC, as the root user. You can either use sudo before every command, or sudo su to change to the root user. As noted above, we are assuming that the SMB/CIFS Share has already been created. Perhaps I will write an article on that later...

To start, be sure to have Client-Server access through TCP Port 445. If you are doing this at home, or where the server will be on the same subnet as the client, this will likely be a non-issue. But if you have to pass through a firewall (or anything similar), you will need to open this port. To quickly test this out, you can run the following command:

telnet <ServerIP> 445

If you get a connection error, you cannot connect; check your routes and firewall(s) and basic connectivity.

So, now that we have ensured we have basic connectivity, let us first manually mount the SMB/CIFS Share, to make sure we use all the proper details:

mount -t smbfs -o username=<user> //<ServerIP>/<ShareFolder> /<LocalMountPoint>

or

mount -t cifs -o username=<user> //<ServerIP>/<ShareFolder> /<LocalMountPoint>

You should then get a prompt for your password. Enter it, then run the following commands to ensure it is good:

touch /<LocalMountPoint>/test.file

ls /<LocalMountPoint>

You *SHOULD* see the 'test.file' file in the output (as well as any existing files on the Share). If you get any errors, address those (there are so many possible errors and misconfigurations, I can't possibly try to list them here. Trust your Google-fu, and you'll find the answer).

Assuming all went fine, let us now unmout the share:

umount /<LocalMountPoint>

Now, we edit the 'fstab' file to ensure it mounts at boot time:

nano /etc/fstab

And add the following line to the bottom:

//<ServerIP>/<ShareFolder> /<LocalMountPoint> cifs credentials=/root/.smbcreds,iocharset=utf8,sec=ntlm 0 0

Next, create the credentials file:

nano /root/.smbcreds

Add the following lines:

username=<user>
password=<pass>

Change the file permissions so only the root user can see the contents:

chmod 600 /root/.smbcreds

Lastly, it is a matter of making sure that it still works. Run the command:

mount -a

And take a look at your <LocalMountPoint>. You should now see the contents of that Shared folder. And next time you reboot this computer, that shared folder will automatically re-mount at that same point. Let me know what you think in the comments below!

Add comment


Security code
Refresh

0
0
0
s2sdefault