Share files and Folders between Linux and Windows on a network
Learn how to effortlessly share files and folders between Linux and Windows machines using Samba.
Sharing files and folders between Linux and Windows machines on the same network can significantly improve collaboration. In this comprehensive guide, we'll take you through the process step by step.
Prerequisites
Make sure your Linux machine (in this case Ubuntu) and Windows machines are connected to the same network.
In Windows
Configuring Windows for File Sharing
To enable file and printer sharing and network discovery on your Windows machine:
- Open the Control Panel.
- Navigate to "Network and Internet."
- Find "Network and Sharing Center."
- Click on "Change advanced sharing settings."
- Turn on "Turn on network discovery" and "Turn on file and printer sharing." under Private Section.
- Under All Network, "Turn on password protected sharing" for the literal job.
- Save changes.
In Linux
Step 1: Install Samba on Ubuntu
Firstly, check your Ubuntu machine's hostname:
hostname
Update your system:
Its always a good practice to up date your system before installing new package.
sudo apt update
Install Samba, a utility package for file and folder sharing:
sudo apt install samba -y
Start the Samba service:
sudo systemctl enable --now smbd
Check the service status:
sudo systemctl status samba
You should see "active (running)" in the terminal.
Step 2: Create a Shared Folder
Navigate to your home directory and create a folder named "shared_folder":
mkdir shared_folder
Check the folder and its access privileges:
ls -l
You will find it only has access privileages of root.
Step 3: Create a Samba Username and Password
Create a Samba user:
sudo smbpasswd -a [anyusername]
Replace "[anyusername]" with your desired username.
Step 4: Edit Samba Configuration
Open the Samba configuration file for editing:
sudo nano /etc/samba/smb.conf
Scroll to the bottom and add the following configuration for the shared folder:
[shared_folder]
path = /home/[your_username]/shared_folder
read only = no
valid users = [your_username]
Save and exit nano by pressing Ctrl + X then Y and Enter.
Restart the Samba service:
sudo systemctl restart smbd
Step 5: Access Shared Folder from Windows
Open File Explorer and type the Linux IP address in the address bar:
\\[your Linux IP address]
[Note]: Enter the Samba credentials when prompted. Now, you can access and work with files in the shared folder from both Linux and Windows.
Creating a Public Folder
If you want a public folder accessible without a password, follow these additional steps:
Create a public folder in the root directory:
sudo mkdir /public_folder
Change ownership to nobody (an ordinary user, not privileged):
sudo chown nobody:nogroup /public_folder/
Give write permissions to group and others:
sudo chmod g+w, o+w /public_folder/
Edit Samba configuration for the public folder:
sudo nano /etc/samba/smb.conf
Add the following configuration at the end:
[public_folder]
path = /public_folder
guest ok = yes
read only = no
force user = nobody
Save and exit nano by pressing Ctrl + X then Y and Enter.
Restart the Samba service:
sudo systemctl restart smbd
Now, you have a public folder accessible without a password. Enjoy seamless file sharing between your Linux and Windows machines!