Sharing files and directories between Linux and Windows systems can be challenging, but with the right tools and configuration, it’s straightforward. This guide covers both directions: making a Linux directory accessible from Windows, and accessing Windows shared directories from Linux.
Sharing a Linux Directory to Windows
Overview: We’ll use Samba, a free and open-source implementation of the SMB/CIFS protocol. This allows Windows computers to access Linux folders as if they were Windows network shares.
To make a Linux folder accessible to Windows computers on your network, follow these steps:
Step 1: Install Samba
1 2 | $ sudo apt-get install samba $ sudo smbpasswd -a USERNAME |
💡 Tip: The smbpasswd command sets a password specifically for Samba — this is separate from your Linux user password. You’ll use this password when connecting from Windows.
Step 2: Create the Shared Directory
1 | $ mkdir /home/USERNAME/sharedfolder |
Step 3: Configure Samba
Edit the Samba configuration file:
1 | $ sudo vi /etc/samba/smb.conf |
Add the following configuration block at the end:
1 2 3 4 5 6 7 8 | [sharedfolder] path = /home/USERNAME/sharedfolder available = yes valid users = USERNAME read only = no browsable = yes public = yes writable = yes |
🔍 Why this works: The section [sharedfolder] defines a new share. The path specifies what Linux directory to expose. valid users restricts access to that Linux user. writable = yes allows Windows users to write to the share.
Step 4: Restart the Samba Service
1 | $ sudo systemctl restart smbd |
Your Linux directory is now visible as a network share on Windows. Browse to \\<linux-ip-address>\sharedfolder in Windows Explorer and authenticate with the Samba username and password.
Reference: Samba Official Documentation, AskUbuntu: Can’t access Ubuntu’s shared folders from Windows 7
Accessing Windows Shared Directories from Linux
Overview: We’ll use CIFS (Common Internet File System), the SMB/CIFS client for Linux. This protocol allows Linux to connect to Windows shares and mount them as local folders.
To mount a Windows shared directory on your Linux system:
1 | sudo mount -t cifs //192.168.1.101/sharedirectoryabc -o username=YOURUSERNAME,password=YOURPASSWORD /home/userabc/sharedirectoryabc |
Replace the IP address, share name, username, password, and mount point with your actual values.
⚠️ Heads up: Storing your password in plain text in the command history is a security risk. For a one-time mount, consider using sudo mount -t cifs -o user which will prompt for the password interactively. For permanent mounts, use a credentials file with restricted permissions (see next section).
Permanent Mount (Optional):
To automatically mount a Windows share at boot, add an entry to /etc/fstab:
1 | sudo vi /etc/fstab |
Add this line:
1 | //192.168.1.101/sharedirectoryabc /home/userabc/sharedirectoryabc cifs username=YOURUSERNAME,password=YOURPASSWORD,uid=1000,gid=1000 0 0 |
Then mount it:
1 | sudo mount -a |
🐧 Note: Replace uid=1000 and gid=1000 with your actual user/group IDs (run id to check). This ensures the mounted share has the correct ownership for your user account.