How to Transfer or Share Files Between Windows and Linux

To share files between Windows and Linux, it’s necessary to have Samba installed on the Linux distro. Samba is an open-source application suite that implements the Server Message Block (SMB) protocol. This allows seamless interoperability between Linux and Windows.

While you can use these other tools to share files between Windows and Linux machines (e.g. FTP, SFTP, SSH), Samba is preferable as it also allows sharing of printers and makes networking between the Windows and Linux machines transparent. The default port for Samba is port 445.

This article explains how to configure Windows to access Linux, as well as how to configure Linux to access Windows.

We’re using Ubuntu LTS 22.04, codenamed Jammy Jellyfish, an Ubuntu-based distro derived from Debian, and Windows 10 for this guide.

Configure Windows and Enable Sharing

  1. Open Settings by clicking on the Start menu and searching for “Settings”.

    Search for and select Settings from the Windows menu.
    Search for and select Settings from the Windows menu.

  2. Select Network & Internet.

    Select Network and Internet from the Settings menu.
    Select Network and Internet.

  3. Select the Network and Sharing Center.

    Select Network and Sharing.
    Select Network and Sharing.

  4. Select the Change advanced sharing settings option. Check the box next to Turn on network discovery. Select Turn on automatic setup of network connected devices. Next, click Turn on file and print sharing. Click Save Changes.

    Select Advanced network sharing and turn on both network discovery and file and print sharing.
    Turn on both network discovery and file and print sharing.

  5. Right-click anywhere in your folder and choose New > Folder. In this instance, the shared folder, samba-share (you can choose any name you like), is being created on the desktop.

    Make a new folder in the desired directory.
    Make a new folder in the desired directory.

  6. Give your folder a name.

    Name your new folder.
    Name your new folder.

  7. Right-click the newly-created folder and choose Properties. In the General tab, unselect the Read-only attribute. Then, click on the Sharing tab.

    Right-click the new folder and choose Properties.
    Right-click the new folder and choose Properties.

  8. In the Sharing tab, select Share this folder and choose Advanced sharing, which allows you to choose individual permissions.

    Select share this folder.
    Select share this folder.

  9. enter the share name, samba-share, and select Permissions.

    Under the Sharing tab, choose Advanced sharing.
    Under the Sharing tab, choose Advanced sharing.

  10. Select the Permissions button, and add the Samba user, in this case, techobservatory. Give the user Full Control.

    Select the Permissions button, and add the Samba user.
    Select the Permissions button, and add the Samba user.

Configure Linux and Enable Sharing

  1. Login to your Linux machine as an admin and launch the terminal.
  2.  Since Samba is not generally installed on Linux distros, it must be installed by the Linux user or administrator. To install on Debian- and Ubuntu-based distros:
    # apt install samba smbclient cifs-utils
    Install Samba and associateed utilites from the command line.
    Install Samba and associated utilities from the command line.

    On RHEL- and CentOS-based distros:

    # rpm -qa samba smbclient cifs-utils

    On Arch-based distros:

    # pacman -Qi samba smbclient cifs-utils
  3. Click “Y” when prompted.
  4. Setup user as a Samba user. A user can only be added as a Samba user if the user already exists on the Linux distro. In this case, techobservatory. To add the user as a Samba user:
    # smbpasswd -a techobservatory

    Add the user as a Samba user.
    Add the user as a Samba user.

  5. Create the directory where you want to mount the share. Note, while we’re using samba-share as the share name,  you can choose any name you like.
    # mkdir /home/techobservatory/samba-share
  6. Mount the newly-created share, /home/techobservatory/samba-share.
    # mount.cifs //192.168.1.235/samba-share /home/techobservatory/samba-share -o user=techobservatory
  7. Make sure the directory was properly mounted:
    # df

    Mount samba-share.
    Mount samba-share.

  8. Next, edit the /etc/samba/smb.conf file. Add the following entries to the end of the file:
    [samba-share]
    path = /home/techobservatory/samba-share
    available = yes
    valid users = techobservatory
    read only = no
    browsable = yes
    public = yes
    writable = yes

    Edit /etc/samba/smb.conf and add the provided entries. Save the file.
    Edit /etc/samba/smb.conf and add the provided entries. Save the file.

  9. We’ll have to restart the samba service for the changes in the /etc/samba/smb.conf. We’ll also enable it so that it starts every time, as well as check the status.
    # systemctl restart smbd
    
    # systemctl enable smbd
    
    # systemctl status smbd

    Start, enable and check the status of Samba.
    Start, enable and check the status of Samba.

Real-Life Scenario – Access Windows from Linux

  1. From the Linux desktop, launch the File Manager.
  2. In the address field, enter smb://<IP address>/<Shared folder> (smb://192.168.1.235/samba-share).

    Enter smb://<IP address>/<Shared folder> in the Connect To: box and click Connect.
    Enter smb:/// in the Connect to Server box and click Connect.

  3. If prompted, enter the username and password.

    If prompted, enter the username and password.
    If prompted, enter the username and password.

  4.  Files and directories can be created, deleted, and modified by the user, techobservatory.

    The Windows share, samba-share, is accessible from the Linux machine.
    The Windows share, samba-share, is accessible from the Linux machine.

Real-Life Scenario – Access Linux from Windows

  1. On Windows, launch File Explorer
  2. In the address field, enter //<IP address>/<Shared folder> (//192.168.1.135/samba-share).

    how-to-transfer-or-share-files-between-windows-and-linux-
    The Linux share, samba-share, is accessible from the Windows machine.

  3. The Linux share, samba-share, is accessible from the Windows machine. Files and directories can be created, deleted, and modified by the user, techobservatory.

Commands Used In This Article

  • systemctl – control the systemd system and service manager.
    df – report file disk space usage.
    mkdir – make directory.
    mount – mount a filesystem.
    smbpasswd – change a user’s SMB password.
    apt – Debian- and Ubuntu-based command-line interface for the package management system.
    rpm – (Remote Package Manager) package manager to install applications and packages on RHEL- and CentOS-based distros.
    pacman – package manager to install applications on Arch-based systems.

Leave a Comment