Software & AppsOperating SystemLinux

How To Mount a Windows Network Share in Ubuntu Permanently

Ubuntu 4

In this article, we will guide you through the step-by-step process of mounting a Windows network share in Ubuntu permanently. This is a useful operation if you are working in a mixed environment where you are using both Windows and Ubuntu.

Quick Answer

To mount a Windows network share in Ubuntu permanently, you need to install the cifs-utils package, create a mount point, create a credentials file, set permissions for the credentials file, retrieve UID and GID values, edit the fstab file, test the mounting of the network share, and finally test the permanent network share. By following these steps, you can easily access and manage files on the Windows share directly from your Ubuntu system.

Prerequisites

Before we start, make sure you have:

  • A running Ubuntu system (the steps have been tested on Ubuntu 20.04 LTS).
  • A Windows network share that you want to mount.
  • Administrator access on your Ubuntu system.

Step 1: Install Necessary Packages

The first step is to install the necessary packages. We will be using the cifs-utils package, which provides tools and a library to handle the SMB protocol. You can install this package by opening the Terminal and entering the following command:

sudo apt-get install cifs-utils

Step 2: Create Mount Points

Next, we need to create a mount point for the Windows share. This is the directory where the shared files will appear on your Ubuntu system. Use the following commands to create the mount point. Replace “mountName” with the desired name for your mount point.

sudo mkdir /media/mountName
sudo chown userId:userId /media/mountName
sudo chmod 755 /media/mountName

Here, mkdir is used to create a directory, chown to change the ownership of the directory, and chmod to change the permissions of the directory.

Step 3: Create a Credentials File

For security reasons, we will store the Windows login credentials in a separate file. Use the following command to create a file to hold your Windows login credentials. Replace “windowsLoginId” and “windowsPassword” with your actual Windows login credentials.

sudo nano ~/.smbcredentials

Enter the following two lines in the file:

username=windowsLoginId
password=windowsPassword

Press ‘ctrl-x’, then ‘y’, and finally ‘enter’ to exit and save the file.

Step 4: Set Permissions for the Credentials File

To protect your credentials, we will set the permissions of the credentials file so that only the owner can read and write to it.

sudo chmod 600 ~/.smbcredentials

Step 5: Retrieve UID and GID Values

Next, we need to retrieve the user ID (UID) and group ID (GID) values for the current user. These values are used to set the ownership of the mounted files. Use the following command to retrieve these values:

id

Step 6: Edit the fstab File

The fstab file is used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem. We will add a line to this file to define our Windows network share mount.

sudo nano /etc/fstab

At the end of the file, add the following line:

//winServerName/shareName /media/mountName cifs credentials=/home/userId/.smbcredentials,uid=1000,gid=1000,vers=3.0,nounix 0 0

Replace “winServerName” with the name of your Windows server, “shareName” with the name of the shared folder, “mountName” with the name of your mount point, and replace the ‘uid’ and ‘gid’ values with the ones you retrieved earlier.

Step 7: Test the Mounting of the Windows Network Share

Now, let’s test the mounting of the network share. If no errors appear, the mount should appear in the file manager. Check the mount in the file manager for read/write access.

sudo mount -a

Step 8: Test the Permanent Network Share

Finally, to ensure that the network share is permanently mounted, shutdown and reboot your PC, then open the file manager and check if the network share is still accessible.

Conclusion

By following these steps, you should now have a Windows network share permanently mounted in your Ubuntu system. This will allow you to easily access and manage files on the Windows share directly from your Ubuntu system.

Remember to keep your credentials file secure and to use the correct UID and GID values when editing the fstab file. If you encounter any issues, check the syntax of the fstab file and the permissions of the mount point and credentials file.

Can I mount multiple Windows network shares in Ubuntu using this method?

Yes, you can mount multiple Windows network shares in Ubuntu using this method. Simply repeat the steps for each network share, creating separate mount points and credentials files for each share.

Can I access the mounted Windows network share from the command line?

Yes, once the Windows network share is mounted, you can access it from the command line. The mount point acts as a regular directory on your Ubuntu system, so you can navigate to it using the cd command and perform any necessary operations.

How do I unmount the Windows network share?

To unmount the Windows network share, you can use the umount command followed by the mount point. For example, if your mount point is /media/mountName, you can unmount the share using the following command: sudo umount /media/mountName.

Can I change the mount point after it has been created?

Yes, you can change the mount point after it has been created. Simply rename the existing mount point directory using the mv command and create a new directory with the desired name using the mkdir command. Make sure to update the fstab file with the new mount point path.

Can I mount a Windows network share without providing credentials?

No, you need to provide valid Windows login credentials to mount a Windows network share. The credentials are stored in the ~/.smbcredentials file, which is used to authenticate and access the share.

Leave a Comment

Your email address will not be published. Required fields are marked *