Mounting windows share ubuntu

How to Mount Windows Share on Ubuntu Linux

CIFS (Common Internet File System) is a popular file sharing protocol on Internet. It allows users on a Linux system access to a particular mount point on a windows share.

CIFS is an implementation of SMB (Server Message Block) — a protocol used for network file sharing.

This tutorial will go through all steps of installing and configuring relevant utilities in order to mount windows share on Linux system.

Installing CIFS

Install cifs-utils package on Ubuntu Linux by using the following command line

Mounting a Windows Share

In this section, the tutorial will show you the way to manually and automatically mount windows share on Linux systems.

Creating a directory on your Ubuntu Linux machine, the name of directory is arbitrary. In the below command line, I created a folder named winshare under /mnt

/mnt/winshare is the mount point of the remote windows share.

Windows share can be mounted on your Ubuntu Linux system mount point using cifs option of mount command

WIN_SHARE_IP is the IP address of windows machine.

If the $windows_user is in a windows domain, specify the domain as the following command line

By default, linux mount windows share with the full permission (rwx or 777). If you want to change the permission on your own, please use the dir_mode and file_mode options to set permission for directory and file.

You also can change the default ownership of user and group by specify the uid (user id) and gid (group id) options.

Once the windows share is successfully mounted, using command df -h for verifying the mounting windows share in Linux. In the following example, WIN_SHARE_IP = 192.168.1.8 and $shared_name = sharefolder

Secure CIFS credential

This section will explain how to use a credential file when your Ubuntu Linux mount the share using command.

Create a cifs credentials file: /etc/cifs-credentials. The file contains the below information:

Grant permission read and write to credentials file:

Now, we can mount the share using credentials with command as follows:

Auto mount the shares

If you manually mount the shares using mount command, when you reboot your Linux machine, the shares will be lost.

The file /etc/fstab contains the necessary configuration that allows automatically mount cifs permanently.

Edit the /etc/fstab file with your favorite editors (vim, nano. )

Then add the following line to the file.

Run the command to mount all the entries listed in /etc/fstab

Since then, the mount cifs will be persistent across reboots.

Unmount the shares

In order to unmount a share, you have to determine the mount point. In the above example, mount point is /mnt/winshare. Use the umount command:

If the mount point is in a busy process and the above command failed, run command with option -l (—lazy)

Conclusion

The tutorial has gone through all steps to mount a windows share on Ubuntu Linux using CIFS. If you have any questions, feel free to reach out to us.

6 Comments. add one

I do not understand why you need to specify the Windows machine IP adress. These are constantly changing when using DHCP, which almost everyone uses. Does that mean that one has to go through the above procedure every day if one wants to connect to a Windows machine whose IP address has changed (people shut off their computers at night, likely getting a new IP address asigned the next day when turned on)? Is there a way that automatically detects the target Windows machine, as Windows does in its own networking system?

If IP address changes, use DNS names

This doesn’t appear to work in the latest ubuntu release.
If I do it from the command line, it requires the «vers=2.0» option.
Not sure how to fix it in the fstab. All I get is error(22) invalid argument.

Читайте также:  Settings about windows phone

What does tail -f /var/log/kern.log shows when you mount?

I’m not sure if it’s the cause of your error, but there’s a typo in the fstab line — where it says «dir_node=0755», it should say «dir_mode=0755». Double check that’s correct in your fstab.

Mount Windows 10 Shares on Ubuntu 18.04 | 16.04

This brief tutorial shows students and new users how to mount Windows shares on Ubuntu 18.04 | 16.04 for all users..

Recently we showed you how to create a public share on Windows system for everyone to access.. If you want to Linux users to access the public shares you created, follow the steps below.

For students or new users looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners..

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

When learning Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using Ubuntu to get work done.…

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses..

To mount Windows shares on Ubuntu, use the steps below;

Step 1: Create Windows Shares

Before you can share a resource, that resource needs to be created and sharing enabled.. This is true for any system. If you don’t enable resource sharing, there can be no sharing.

The first step to share a Windows folder it to create it and share it.. The link below shows you how to do that.

Step 2: Install CIFS Utilities on Ubuntu

Now that you have created a Windows 10 folder and have shared it, go to the Ubuntu computer you wish to access to share from… Then run the commands below to install the CIFS utilities that will enable sharing..

After installing, continue below to create a location on the Ubuntu machine to mount the Windows share..

For this tutorial, we’ll be mounting the share at /mnt/ winshare

Step 3: Create a Mount Point on Ubuntu

After installing the Ubuntu packages that allow for sharing, run the commands below to create a location to mount the Windows share.

This location will be linked to the Windows share on Ubuntu where anyone with access can mount to..

The folder we’ll want to create for the Windows share will be called winshare .

sudo mkdir /mnt/ winshare

Next, run the commands below on the mount point to give everyone access

Step 4: Mount the Windows Share

Now with sudo privileges, you can simply run the commands below to mount the share manually at the /mnt/ winshare location on Ubuntu..

The windows share name created previously on the Windows 10 machine is PublicShares

sudo mount -t cifs -o username= windows_user_account_here // WIN_MACHINE_IP / PublicShares /mnt/ winshare

You will be prompted for the Windows account password.

Once the file is mounted, you can use the mount command to view the mount activities or df -h command..

Use the df -h command to list the mount:

df -h /mnt/winshare

You should see similar output as below:

The mount point turns to a directory of the mounted file system for the root account.. You will be able to work with shared files as if they were local to the Ubuntu machine..

Step 5: Automatically Mount the Share on Ubuntu

If you want to automatically mount the shared resource everytime Ubuntu starts up, then you’ll want to add the mount point using the system’s fstab file..

For better security you should use a credentials file with the share username, password and domain for the Windows system.. Do to that, simply run the commands below to created one..

sudo nano /etc/win_cred

Then copy and paste the lines updating with the Windows user accounts with access to the share..

Save the file and exit.

Secure the file using the commands below:

You can then mount the file manually using the credential file created..

Читайте также:  Linux find on http

sudo mount -t cifs -o credentials=/etc/win_cred // WIN_MACHINE_IP / PublicShares /mnt/ winshare

Finally, to mount the share automatically, run the command below to open the system’s fstab file…

sudo nano /etc/fstab

Then add the line below into the file and save.

// WIN_MACHINE_IP / PublicShares /mnt/ winshare cifs credentials=/etc/win_cred,file_mode=0755,dir_mode=0755 0 0

Save the file and exit.

By default, mounted shares are owned by root since you use the sudo command to mount, and the permissions are set to 777.

Use the dir_mode option to set the directory permissions and file_mode to set the file permissions..

The line details:

credentials=/etc/win_cred file contents the windows account username and password to access the Windows share.

file_mode=0755 provides read/write/execute and write/execute for others for files

dir_mode=0755 provides the same rights as above for folders

Now all you have to do to mount the file is run the commands below:

sudo mount /mnt/ winshare

If you’re using Ubuntu desktop, browse to the mount directory and the Windows share should be mounted there..

To un-mount the share, run the commands below:

sudo umount /mnt/ winshare

If the file system is being used the umount command will fail… make sure no one is currently accessing the mount point before unmounting…

Conclusion:

You have learn how to create Windows 10 shares and how to mount them in Ubuntu.. If you find errors, please comment below:

You may also like the post below:

Published by Richard Zayzay

Hi, I’m Richard. In my spare time, I research topics that are interesting and worthwhile for users and students who want to try something new. I, too, am a student and my focus here is to help other students and new users get started with managing Ubuntu Linux, Windows, Content Management Systems (CMS) and others. I try to do my best explaining the topics and detailing the instructions so that anyone can understand. These tutorials may not work in all situations and for all users. However, if you run into trouble, please ask your questions below and I or someone from the community may help you resolve. Thanks for reading and hope you come back.

4 Replies to “Mount Windows 10 Shares on Ubuntu 18.04 | 16.04”

I kept getting a permission denied error when mounting the share using the Windows username/password. My workaround was to create a user on the Windows machine to match my Ubuntu 20.04 LTS username with the Windows password.
Now I’m getting an error trying to permanently mount the share every time the Linux host spins up.

I beat my head against a wall for 30 minutes trying to figure out why I could manually mount the share, but trying to auto mount was giving me a permissions denied error.

It’s because in the example above, the win_cred file has spaces in it. There should not be any spaces before or after the = sign.

username=windows_user_account_name
password=windows_user_password
domain=windows workgroup name

username = windows_user_account_name
password = windows_user_password
domain = windows workgroup name

Once I removed the spaces it worked like a charm.

Mount Windows Shares For Everyone on Ubuntu 17.04 | 17.10

This brief tutorial shows students and new users how to automatically mount Windows shares on Ubuntu 17.04 | 17.10 for everyone to access without prompting for passwords. Yesterday we showed you how to create a public share on Windows system for everyone to access.

This post is going to show you how to automatically mount the Windows shared folder on Ubuntu machines for everyone to access. No passwords needed and everyone body will be able to create, modify and delete files and folders from there shared location.

This setup is is great for environments where you want users to temporarily store content before moving to a more secure location. You don’t want your users storing content for long here since everyone has full rights to create, delete and modify files and folders

To mount Windows shares on Ubuntu automatically, follow the steps below:

Step 1: Create Windows Shares

This first step mounting Windows shares on Ubuntu is to create a Windows share. To do that, read the post below:

Step 2: Install CIFS or SMBFS

Now that you’ve created a Windows share with everyone having full access, run the commands below to install smbfs or cifs package on Ubuntu.

sudo apt-get install cifs-utils

After installing, continue below to create a location to mount the Windows shares.

Читайте также:  Linux how to run as root

Step 3: Create a Mount Point

After installing the Ubuntu packages that allows for sharing between two systems, run the commands below to create a location to mount the Windows share. This location will be linked to the Windows share on Ubuntu with everyone having full access.

The folder we’ll want to create for the Windows share will be called winshare.

sudo mkdir /media/winshare

Next, run the commands below on the mount point to give everyone access

Step 4: Mount the Windows Share

Now that all the requirements are met, run the commands below to open Linux fstab file.

sudo nano /etc/fstab

Then add the line below into the file and save.

// WINDOWSPC/PublicShares /media/winshare cifs username= winuser ,password= winuserpasswd ,uid=nobody,iocharset=utf8,noperm 0 0

Save the file and you’re done.

The line details:

username and password indicates a windows user account and password to access the shared folder.

uid=nobody makes the Linux user specified by the id the owner of the mounted share, allowing anyone access.

iocharset=utf8 allows access to files with names in non-English languages.

Now all you have to do to mount the file is run the commands below:

If you’re using Ubuntu desktop, browse to the mount directory and the Windows share should be mounted there.

Mounting a windows share in Windows Subsystem for Linux

I’d like to mount a windows server from within WSL (Windows Subsystem for Linux). On Ubuntu (with unity interface) I can just type

and everything mounts just fine.

If I try this in WSL then I get the following error:

5 Answers 5

Assuming the host Windows OS can access a file share at «\\servername\sharename», try this command in bash. You will need to be root:

The single quotes are important!

Worked for me with a SharePoint Online UNC path. The permissions are screwy though. I can navigate through the folders and see the filenames, but I can’t read files. So need to figure out the permissions thing. Let me know if you get anywhere with that.

Actually if your windows share is already mapped to a drive in the Windows host, it can be even simpler. Let’s suppose you already mounted the share on Z: . In that case the following will work:

While you have an a mount created to the windows host through /mnt/c already created for you in WSL, if you want to mount a share from another machine, then you will need to create the mount point, e.g.

Then you will need to mount the remotely shared smb:// filesystem at that mount point using mount.cifs , e.g.

Optionally, you will want to include options following /mnt/somename such as

If it is an older WinXP share you are attempting to mount, then you will need to enable NTLMv1 authentication by including the sec=ntlm or sec=ntlm1 . See mount.cifs for further use of the sec= option.

In WSL (I’m using Ubuntu) it looks like that when you install the cifs-utils it doesn’t create the module file that cifs needs when mounting. Type: «modinfo cifs» and you will see. Anyway, the work-around is to map a drive letter in Windows and then mount to that, as mentioned above. Thanks gabuzo.

Maybe its that cifs-utils is looking in the wrong place for the module file. Or MS intentionally disabled it. They don’t want WSL to be too useful.

Mounting an SMB server share should be straightforward, I tested this on Windows build 1909 and WSL 2.0 Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64). You use mount just as usual:

Nothing too hard, the source path of the mount is the regular UNC pathname. The important bits are the file system type («drive filesystem»?) and the fact that you need to enclose the server path in single quotes (on the command line). As usual, your mount folder must also exist.

On this WSL issue I found good options (-o) that seem to work very well with creating, reading and writing files without sudo as well as reading correct modification/creation dates:

Because I like to have this server mounted always, I put the mount instruction into /etc/fstab to have it auto-mounted by WSL:

(you can reload fstab with sudo mount -a )

Note that I have logged into the server on Windows itself and made it remember the user and password. @David C. Rankin’s answer has some info on how to specify username and password if you need to do it separately.

Оцените статью