🔑 Introduction#
CIFS (Common Internet File System) allows you to mount network folders on your Linux system, making it easier to access shared files from Windows machines. In this guide, we’ll walk through the steps to install CIFS, mount unprotected and password-protected shares, and discuss the importance of using credentials files for secure mounting.
Install CIFS 🚀#
To install CIFS, run the following command:
sudo apt-get install cifs-utils
Mount unprotected (guest) network folders 📁#
First, let’s create the mount directory. You will need a separate directory for each mount:
sudo mkdir /media/windowsshare
Then edit your /etc/fstab
file (with root privileges)
sudo nano /etc/fstab
add this line:
//servername/sharename /media/windowsshare cifs guest,uid=1000 0 0
Where:
servername
is the server hostname or IP address 📲,guest
indicates you don’t need a password to access the share 🔒,uid=1000
makes the Linux user (specified by the ID) the owner of the mounted share, allowing them to rename files, andIf there is any space in the server path, you need to replace it by
\040
, for example://servername/My\040Documents
After you add the entry to /etc/fstab
, type:
sudo mount /media/windowsshare
Mount password-protected network folders 🔒#
To auto-mount a password-protected share, you can edit /etc/fstab
(with root privileges), and add this line:
servername/sharename /media/windowsshare cifs username=msusername,password=mspassword 0 0
** Warning: ** This is not a good idea however: /etc/fstab
is readable by everyone – and so is your Windows password within it. The way around this is to use a credentials
file.
Create a credentials file 🔒#
Using a text editor, create a file for your remote server’s logon credential:
sudo nano ~/.smbcredentials
Enter your Windows username and password in the file:
username=username
password=password
Save the file and exit the editor.
Change the permissions of the file to prevent unwanted access to your credentials:
chmod 600 ~/.smbcredentials
Then edit your /etc/fstab
file (with root privileges) to add this line (replacing the insecure line in the example above, if you added it):
//servername/sharename /media/windowsshare cifs credentials=/home/ubuntuusername/.smbcredentials 0 0
Save the file and exit the editor.
Finally, test mounting the share by running:
sudo mount /media/windowsshare
If there are no errors, you should test how it works after a reboot. Your remote share should mount automatically. However, if the remote server goes offline, the boot process could present errors because it won’t be possible to mount the share 😬.
Conclusion: 🎉#
You now know how to mount network folders on your Linux system using CIFS! With these simple steps, you can access your Windows shares without having to physically connect a cable. Remember to use a credentials file for password-protected shares to keep your passwords safe 🔒. Happy mounting! 😊