Share Files Between Windows and Linux


To totally unlock this section you need to Log-in


Login

There are basically two parts to this guide: creating the shared folder on Windows and configuring Linux to access it, and creating the shared folder on Linux and configuring Windows to access it. Depending on your situation, you’ll want to follow the appropriate set of instructions. If, for some reason, you want to set up shared folders on both systems, you can do that, too. This guide will cover Windows 8.1 and Ubuntu, but this will be adaptable to virtually any version of Windows or Linux.

Creating the Share on Windows

To set up a shared folder on Windows for Linux to access, start by making sure your network settings are configured to allow the connection from the other computer by opening the Network and Sharing Center.

Share Files Between Windows and Linux

In the Network and Sharing Center window, click on "Change advanced sharing settings".

Share Files Between Windows and Linux

For your current profile, adjust the following two settings:

  • Turn on network discovery.
  • Turn on file and printer sharing.

Share Files Between Windows and Linux

Click on “Save Changes” after those settings are configured. Now we can create a place on the Windows computer for the Linux machine to see files and copy contents to. There are no limitations to what you can share out (you could theoretically share your entire hard drive), but we will just be sharing out a folder called “Share” located on our Desktop.

Right click on the folder you’d like to share out over the network, and click Properties. Go to the Sharing tab and click Advanced Sharing.

Share Files Between Windows and Linux

Check the “Share this folder” box and click on “Permissions” toward the bottom.

Share Files Between Windows and Linux

In the Permissions window, you can restrict access to the folder for certain accounts. To let any user have access to your folder, just give Full Control to the Everyone user. This will allow anyone to read and write changes to the shared folder. If you would rather restrict access to certain accounts, just remove the Everyone user and add the users you’d like to grant access to.

NOTE: These user accounts are on the Windows computer, not Linux.

Share Files Between Windows and Linux

Click OK on the Permissions and Advanced Sharing windows once you’ve made your changes. While still in the Properties menu, click on the Security tab.

Share Files Between Windows and Linux

For the Linux user to have access to the shared folder, the same permissions need to be configured in this tab as what we configured in the sharing settings. If the two settings don’t match, the most restrictive settings are the ones that will take effect. If your desired user already has their security permissions set up (such as the geek user in our example) then you’re good to go and can click Close.

If you need to add a user, such as Everyone, click on Edit.

Share Files Between Windows and Linux

Click on Add in the next menu, enter the username, and click OK.

Share Files Between Windows and Linux

Click OK on all the open windows, and your folder should now be shared out and accessible on your Linux computer.

Accessing the Windows Share from Linux

You should be able to mount the shared folder by using the GUI in Linux, but it’s also very easy to do with the command line, and it’s easier to show a terminal example because it will work across many different distributions.

You’ll need the cifs-utils package in order to mount SMB shares:

sudo apt-get install cifs-utils

After that, just make a directory and mount the share to it. In this example, we will mount the folder to our Desktop for easy access.

mkdir ~/Desktop/Windows-Share

sudo mount.cifs //WindowsPC/Share /home/geek/Desktop/Windows-Share -o user=geek

Share Files Between Windows and Linux

As you can see in the screenshot, we were prompted for the root password of the Linux machine, and then the password for the ‘geek’ account on Windows. After running that command, we are now able to see the contents of the Windows share and add data to it.

In case you need help understanding the mount command, here’s a breakdown:

sudo mount.cifs – This is just the mount command, set to mount a CIFS (SMB) share.

WindowsPC – This is the name of the Windows computer. Type “This PC” into the Start menu on Windows, right click it, and go to Properties to see your computer name.

Share Files Between Windows and Linux

//Windows-PC/Share – This is the full path to the shared folder.

/home/geek/Desktop/Windows-Share – This is where we’d like the share to be mounted.

-o user=geek – This is the Windows username that we are using to access the shared folder.

Creating the Share on Linux

To set up a shared folder on Linux for Windows to access, start with installing Samba.

sudo apt-get install samba

After Samba installs, configure a username and password that will be used to access the share.

smbpasswd -a geek

Note: In this example, we are using ‘geek’ since we already have a Linux user with that name – but you can choose any name you’d like.

Share Files Between Windows and Linux

Create the directory that you’d like to share out to your Windows computer. We’re just going to put a folder on our Desktop.

mkdir ~/Desktop/Share

Now, use your favorite editor to configure the smb.conf file.

sudo vi /etc/samba/smb.conf

Scroll down to the end of the file and add these lines:

[]
path = /home//
available = yes
valid users = 
read only = no
browsable = yes
public = yes
writable = yes

Obviously, you will need to replace some of the values with your personal settings. It should look something like this:

Share Files Between Windows and Linux

Save the file and close your editor. Now, restart the SMB service for the changes to take effect.

sudo service smbd restart

Your shared folder should now be accessible from a Windows PC.

Accessing the Linux Share from Windows

Now, let’s add the Linux share to our Windows Desktop. Right-click somewhere on your Desktop and go to New > Shortcut.

Share Files Between Windows and Linux

Type in the network location of the shared folder, with this syntax:

\\IP-ADDRESS\SHARE-NAME

If you need the IP of your Linux computer, just issue the following command:

ifconfig

Click Next, choose a name for the Shortcut, and click Finish. You should end up with a Shortcut on your Desktop that goes right to the Linux share.

Access a Windows shared folder from Linux, using the command line

You can also access your Windows share from the Linux command line using the smbclient command line program.

  1. Open a terminal.
  2. Type smbclient at the command prompt.
  3. If you receive a "Usage:" message, this means smbclient is installed, and you can skip to the next step. If the command is not found, however, you need to install smbclient.
  4. Once you're sure that smbclient is installed, you can connect to your Windows share using the command:
  5. smbclient //ComputerName/ShareName -U Username
    

    For instance, if your Windows user name is Fred and your Windows share network name was listed as:

    \\YOURCOMPUTERNAME\Users\YourUserName\ShareFolderName
    

    You should use the command:

    smbclient //YOURCOMPUTERNAME/Users/YourUserName/ShareFolderName -U Fred. 
    

    Notice that the Linux command uses forward slashes instead of backslashes.

  6. Enter your password.
  7. Once authenticated, you are placed at an smb: \> prompt.
  8. Here, you can use the ls command to list files.
  9. Use the command get filename.ext to transfer a file named filename.ext from your Windows share to your Linux machine, for example.
  10. Type help for a listing of further commands.
  11. Type quit or exit to return to the command prompt.

NOTE: To install smbclient:

  • If you use the apt package manager, which is the default on Linux systems such as Ubuntu or Debian, you can use the sudo apt-get install smbclient command.
  • If you use the yum package manager, which is the default on Linux systems such as CentOS or Fedora, you can use the sudo yum install samba-client command.

You can also download the Samba client directly at www.samba.org/samba/download/ which might be useful to you if you need or want to compile the program from the source code.