Install Samba: Use sudo apt update and sudo apt install samba samba-common-bin on Ubuntu/Debian, and use sudo dnf install samba on CentOS/RHEL; 2. Create a shared directory: Use sudo mkdir -p /srv/samba/shared and set permissions chmod -R 0775 and owner chown -R nobody:nogroup; 3. Configure smb.conf: Add a shared configuration at the end of /etc/samba/smb.conf file, including path, browsing, writable, guest permissions, etc.; 4. Set Samba user: Use sudo adduser to create system users, and then use sudo smbpasswd -a to add and enable Samba password. If you disable the visitor, you need to specify valid in the configuration. users; 5. Start the service: Use sudo systemctl restart and enable to start and enable smbd and nmbd services; 6. Firewall settings: Run sudo ufw allow 'Samba' on UFW, use sudo firewall-cmd --permanent --add-service=samba on firewalld and overload; 7. Test sharing: Access through \your-server-ip\shared in Windows, use smbclient test on Linux, and use testparm to check configuration file syntax; finally ensure that guest access is turned off in production environment and monitor logs to ensure security, this configuration implements file sharing across operating systems.
Setting up a Samba share on a Linux server allows you to easily share files between Linux and Windows machines on the same network. It's a reliable way to create a centralized file storage location that's accessible across different operating systems. Here's how to set it up step by step.

1. Install Samba on Your Linux Server
First, make sure your system is up to date, then install the Samba package.
On Ubuntu/Debian :

sudo apt update sudo apt install samba samba-common-bin
On CentOS/RHEL/Rocky Linux :
sudo dnf install samba samba-common samba-client
After installation, the Samba service ( smbd
) will be available, but it won't start automatically until configured.

2. Create a Directory to Share
Decide where you want to store shared files. For example:
sudo mkdir -p /srv/samba/shared
Set appropriate permissions so that the Samba users can access it:
sudo chmod -R 0775 /srv/samba/shared sudo chown -R nobody:nogroup /srv/samba/shared
Note: Using
nobody:nogroup
is fine for guest-access shares. For user-restricted shares, use a specific user and group.
3. Configure the Samba Settings
Edit the main Samba configuration file:
sudo nano /etc/samba/smb.conf
At the end of the file, add your share definition. Here's an example of a simple, open share:
[shared] path = /srv/samba/shared browser = yes writable = yes guest ok = yes read only = no create mask = 0644 directory mask = 0755
Key Options Explained:
-
browsable = yes
– Makes the share visible on the network. -
writable = yes
– Allows file uploads and edits. -
guest ok = yes
– Lets users access without a password (use carefully). -
read only = no
– Same aswritable = yes
, just different syntax. -
create mask
anddirectory mask
– Set default permissions for new files and folders.
?? For a more secure setup, disable guest access and require user authentication.
4. Set Up Samba User Accounts
If you disable guest access, you'll need to add users with Samba passwords.
First, ensure the user exists on the Linux system:
sudo adduser username
Then add them to Samba:
sudo smbpasswd -a username
Enable the user:
sudo smbpasswd -e username
In smb.conf
, modify the share to require authentication:
[shared] path = /srv/samba/shared browser = yes writable = yes guest ok = no valid users = username
5. Start and Enable the Samba Service
Once configured, restart Samba to apply changes.
On most systems:
sudo systemctl restart smbd sudo systemctl enable smbd
Also, start and enable nmbd
(NetBIOS name resolution):
sudo systemctl restart nmbd sudo systemctl enable nmbd
6. Configure Firewall Access
Allow Samba through the firewall.
On UFW (Ubuntu) :
sudo ufw allows 'Samba'
On firewalld (CentOS/RHEL) :
sudo firewall-cmd --permanent --add-service=samba sudo firewall-cmd --reload
7. Test the Share
From a Windows machine:
- Open File Explorer.
- In the address bar, type:
\\your-server-ip\shared
- If guest access is on, it should open directly.
- If using user auth, you'll be prompted to log in.
From another Linux machine:
smbclient //localhost/shared -U username
You can also test locally:
testparm
This checks for syntax errors in smb.conf
.
Final Notes
- Always consider security: Avoid
guest ok = yes
in production or untrusted networks. - Monitor logs at
/var/log/samba/
if something isn't working. - You can create multiple shares by repeating the config block with different names and paths.
Basically, that's it — you now have a working Samba share accessible across your network.
The above is the detailed content of How to set up a Samba Share on a Linux Server. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and
