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
- Open Settings by clicking on the Start menu and searching for “Settings”.
- Select Network & Internet.
- Select the Network and Sharing Center.
- 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.
- 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.
- Give your folder a name.
- Right-click the newly-created folder and choose Properties. In the General tab, unselect the Read-only attribute. Then, click on the Sharing tab.
- In the Sharing tab, select Share this folder and choose Advanced sharing, which allows you to choose individual permissions.
- enter the share name, samba-share, and select Permissions.
- Select the Permissions button, and add the Samba user, in this case, techobservatory. Give the user Full Control.
Configure Linux and Enable Sharing
- Login to your Linux machine as an admin and launch the terminal.
- 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
On RHEL- and CentOS-based distros:
# rpm -qa samba smbclient cifs-utils
On Arch-based distros:
# pacman -Qi samba smbclient cifs-utils
- Click “Y” when prompted.
- 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
- 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
- Mount the newly-created share, /home/techobservatory/samba-share.
# mount.cifs //192.168.1.235/samba-share /home/techobservatory/samba-share -o user=techobservatory
- Make sure the directory was properly mounted:
- 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
- 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
Real-Life Scenario – Access Windows from Linux
- From the Linux desktop, launch the File Manager.
- In the address field, enter smb://<IP address>/<Shared folder> (smb://192.168.1.235/samba-share).
- If prompted, enter the username and password.
- Files and directories can be created, deleted, and modified by the user, techobservatory.
Real-Life Scenario – Access Linux from Windows
- On Windows, launch File Explorer
- In the address field, enter //<IP address>/<Shared folder> (//192.168.1.135/samba-share).
- 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.