← Back to articles

11.07.2025

Creating and Configuring Network Shared Folders in Linux (Samba)


To set up shared network folders using the SMB/CIFS protocol, install the samba package:

user@COMPXX:~\$ sudo apt-get update && sudo apt-get install -y samba

Creating the Directory and Setting Permissions

Create a folder for shared access (for example, /SHARE in the root directory) and set its owner to www-data (this is useful if files from the network share will also be accessed by a web server):

user@COMPXX:~\$ sudo mkdir -p /SHARE
user@COMPXX:~\$ sudo chown -R www-data:www-data /SHARE
user@COMPXX:~\$ sudo chmod -R 0775 /SHARE

Configuring Samba

Before making changes, create a backup of the default /etc/samba/smb.conf configuration file:

user@COMPXX:~\$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Open the configuration file for editing:

user@COMPXX:~\$ sudo nano /etc/samba/smb.conf

Make sure guest access support (map to guest = bad user) is enabled in the [global] section, and add your [SHARE] folder definition at the very end of the file:

[global]
    workgroup = WORKGROUP
    security = user
    map to guest = bad user
    wins support = no
    dns proxy = no

[SHARE]
    path = /SHARE
    browsable = yes
    writable = yes
    guest ok = yes
    force user = www-data
    force group = www-data
    create mask = 0664
    directory mask = 0775

Important: Using guest ok = yes grants full read and write access without a password to all devices on the network. Use this configuration only in a trusted local network and never expose Samba ports to the public internet.

Testing and Starting the Services

Verify the configuration file syntax using the built-in testparm utility:

user@COMPXX:~\$ testparm -s

If there are no errors, allow Samba traffic through the firewall (if UFW is enabled):

user@COMPXX:~\$ sudo ufw allow Samba

Restart the smbd and nmbd services to apply the changes and enable them at boot:

user@COMPXX:~\$ sudo systemctl restart smbd nmbd
user@COMPXX:~\$ sudo systemctl enable smbd nmbd

Testing Access

You can now verify access to the shared folder from another computer on your local network:
* Windows: Open File Explorer and enter \\SERVER_IP_ADDRESS in the address bar (for example, \\192.168.1.50).
* Linux / macOS: Open your file manager and connect to smb://SERVER_IP_ADDRESS/SHARE.

If the SHARE network resource appears in the list and you can create files inside it, the setup is complete.

Note for Windows 10 / 11: Modern editions of Windows (Pro, Enterprise) block unauthenticated guest access to SMB shares by default due to security policies. If Windows denies access without credentials, either configure password-protected access via sudo smbpasswd -a username, or allow insecure guest logons in the Windows Local Group Policy Editor (gpedit.msc → Computer Configuration → Administrative Templates → Network → Lanman Workstation → Enable insecure guest logons).