Linux Configuring Samba Service Tutorial
Installing Samba
1 | apt update |
Configuring Samba
Samba’s configuration file is usually located at /etc/samba/smb.conf
. You can use a text editor (such as nano
or vim
) to edit this file. Add shared files.
Remember to back up the file before modifying
1 | cp /etc/samba/smb.conf /etc/samba/smb.conf.bak |
1 | [shared] |
comment
: Description of the shared directory.path
: Path of the shared directory.valid users
: Users allowed to access this shared directory.read only
: Set tono
to allow writing.browsable
: Set toyes
to make the shared directory visible in the network.create mask
anddirectory mask
: Set the permissions for files and directories.
Creating Samba User
Samba uses its own user database for authentication. You need to create a user for Samba and set a password.
1 |
|
The system will prompt you to enter and confirm the password.
Starting and Enabling Samba Service
After configuration is complete, you need to start the Samba service and set it to start automatically on system boot.
On Debian/Ubuntu:
1 | sudo systemctl start smbd |
On CentOS/RHEL:
1 | sudo systemctl start smb |
Firewall Configuration
If your system has a firewall enabled (such as ufw
or firewalld
), you need to allow the Samba service through the firewall.
On Debian/Ubuntu (using ufw
):
1 | sudo ufw allow samba |
On CentOS/RHEL (using firewalld
):
1 | sudo firewall-cmd --permanent --add-service=samba |
Testing Samba Configuration
You can use the testparm
command to check for syntax errors in the Samba configuration file.
1 | testparm |
If there are no errors, the Samba service should be successfully configured and running.
Accessing Shared Directory
On Windows, you can access the Samba shared directory by entering \\<server IP address>
in File Explorer. On Linux, you can use smbclient
or mount
command to access the shared directory.
1 | # Using smbclient |
If you encounter any problems, you can check the Samba log files (usually located at /var/log/samba/
) for more information.