Frequently Asked Question
Samba (SMB) Server on Linux
Last Updated 3 hours ago
Samba (SMB) Server on Linux
How to Install Samba Server on Debian/RHEL and Configure Users
Prerequisites:
- A Debian or RHEL server.
- Administrative privileges.
For Debian (e.g., Ubuntu):
sudo apt update
- Update the package list:
sudo apt install samba
- Install Samba:
For Red Hat Enterprise Linux (RHEL) or CentOS:
sudo yum install -y samba
sudo systemctl enable smb
sudo systemctl start smb
- Enable and start the Samba service:
sudo yum install -y samba-common-tools
- Install additional packages for security and management:
Step 2: Configure Samba
Editing /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
- Open the configuration file:
- Add or modify the following sections:
Global settings:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = YOURSERVERNAME
security = user
map to guest = bad user
Shared directory (e.g., /srv/smbshare):
[smbshare]
path = /srv/smbshare
valid users = johndoe jane_doe
read only = no
browsable = yes
guest ok = no
- Save and exit the file.
Step 3: Add Users to Samba
sudo useradd -M johndoe -s /sbin/nologin
- Create a new user (e.g.,
johndoe):
sudo smbpasswd -a johndoe
- Set a password for the user:
- Repeat steps 1 and 2 for other users (
jane_doein this example).
Step 4: Testing with smbclient
To test the Samba share, you can use the smbclient tool.
Test from a Windows machine:
smbclient \\\\<SERVER_IP>\smbshare -U johndoe%password
Test from Linux (using smbclient):
smbclient //<SERVER_IP>/smbshare -U johndoe%password -c "ls"
This command lists the contents of the shared directory, confirming that Samba is working correctly.
Conclusion
You have successfully installed and configured a Samba server on your Debian or RHEL machine. Testing with smbclient ensures that users can access the shared directory as intended.
