There is probably not a single office that does not use shared local network resources, whether they are folders or printers. Large and medium-sized companies use the capabilities of Active Directory, while smaller companies use regular Windows or Samba tools on Linux servers. Let’s review all these cases.
How to configure Samba:
- What is Samba?
- How to set up a shared folder
- a) How to set up a shared folder in Linux
- b) How to set up a shared folder on Windows
- How to connect to a shared folder
- a) How to connect to a Linux shared folder
- b) How to connect to a Windows shared folder
- How to create a Network Share in Samba
What is Samba?
Samba is a server application that enables client computers to access shared folders, printers, and disks over the SMB/CIFS protocol, allowing seamless file and resource sharing between Linux and Windows systems.
Configuring shared folders
Linux
The installation and configuration of the Samba server on Ubuntu involves the following steps:
Update package information and upgrade existing software:
Install Samba and its client utilities:
Backup the default Samba configuration file:
Create the base directory for Samba shares, e.g., under /media:
Important: By default, /media is part of the root partition, which may have limited space. To prevent disk space issues, it's recommended to mount a separate partition or drive at /media/samba.
Create a public directory accessible to all users:
Set appropriate permissions for the public folder:
(Optional) Change ownership or group with chown or chgrp if needed.
Create a private directory for restricted access:
Create a user group to manage access:
Add Samba users:
Add users to the group:
Assign the private directory to the group:
Set Samba passwords for the users:
Edit Samba configuration:
Clear the file and insert:
workgroup = WORKGROUP
security = user
map to guest = bad user
wins support = no
dns proxy = no
[public]
path = /media/samba/public
guest ok = yes
force user = nobody
browsable = yes
writable = yes
[private]
path = /media/samba/private
valid users = @smbgrp
guest ok = no
browsable = yes
writable = yes
Save with Ctrl + X, then Y, then Enter.
Explanation of important parameters:
- global — general server settings.
- public and private — define shared folders and their access rules.
- Parameters in the global section:
- workgroup — network workgroup name (default: WORKGROUP). Change if your network uses a different name.
- security — server authentication mode ("user" means username/password required).
- map to guest — handles invalid login attempts ("bad user" rejects incorrect passwords).
- wins support — enable/disable WINS server functionality.
- dns proxy — enable/disable DNS proxying.
- Parameters for each shared directory:
- path — absolute path to the shared folder.
- guest ok — allow guest (unauthenticated) access.
- browsable — whether the share is visible when browsing.
- force user — force all file operations to be performed by a specified user (usually "nobody" for security).
- writable — allow write operations.
- valid users — restrict access to specific users or groups (groups prefixed with @).
Check the Samba configuration for syntax errors:
Restart Samba services:
service nmbd restart
Configure firewall rules to allow Samba ports, restricting access to trusted subnets only:
iptables -A INPUT -p tcp --dport 139 -s 10.0.0.0/24 -j ACCEPT
iptables -A INPUT -p udp --dport 137 -s 10.0.0.0/24 -j ACCEPT
iptables -A INPUT -p udp --dport 138 -s 10.0.0.0/24 -j ACCEPT
To persist firewall rules across reboots, install:
During installation, confirm saving current rules.
Verify current firewall rules with:
Windows
Shared folders setup in Windows is similar but done via GUI:
To share folders without password protection, disable password-protected sharing:
Control Panel → Network and Internet → Network and Sharing Center → Advanced sharing settings → All Networks → Disable "Password protected sharing" → Save changes.
To share a folder:
Right-click folder → Properties → Sharing tab → Advanced Sharing.
Check "Share this folder", set share name.
Click "Permissions", select "Everyone", enable "Full Control", then OK.
Back in Properties, click "Share", add "Everyone" with Read/Write permissions, then Share → Done.
To restrict sharing to specific users:
Right-click folder → Properties → Sharing tab → Advanced Sharing → Share this folder.
Permissions → Remove "Everyone".
Add users/groups by clicking "Add" → Advanced → Find Now → select users/groups.
Assign appropriate permissions.
Confirm all dialogs.
Connecting to shared folders
From Linux
Install smbclient:
Connect to share:
Example:
To mount the share as a network drive automatically, install cifs-utils:
Mount using:
Note: For Windows shares without password, use username "Everyone". For Linux shares, use "nobody" or the assigned username with password for protected shares.
From Windows
To connect to shared folders:
Open File Explorer or press Windows + R.
Enter:
Entering only the IP address lists all available shares.
If prompted for credentials on Windows shares, use username "Everyone" with no password for open shares.
To connect to Linux shares from Windows, use the same UNC path.
How to create a Network Share in Samba
Create the folder to share:
Backup Samba config:
Edit Samba config:
Add at the end:
path = /home//
valid users =
read only = no
Save and exit.
Restart Samba:
Check config syntax:
Access share with smbclient:
smbclient -L /// -U
smbclient /// -U
Notes: