Samba - SMB
Last updated
Last updated
Samba refers to a software suite that allows for file and print services to be shared across different operating systems, specifically between Linux/Unix and Windows systems. Samba implements the Server Message Block (SMB) protocol, which is widely used for sharing files, printers, and other resources in a network.
Update your package list and install Samba:
Verify Samba installation:
Let's configure the shares you need (editable
and readonly
).
Edit the Samba configuration file: Open the smb.conf
file:
Create the shares: Add the following configuration at the end of the smb.conf
file:
editable: This share allows all users to read and write files.
readonly: This share allows all users to read but not modify the files.
Create directories for the shares:
You need to ensure that the user sambauser
exists in the system before adding them to Samba otherwise we cannot set passwords to the samba user.
First, create a system user named sambauser
(if it doesn't already exist) to be used by Samba
The shell /usr/sbin/nologin
ensures that user cannot access shell on the server to harden the security:
sambauser
to Samba DatabaseNow that the user exists, you can proceed with adding sambauser
to the Samba database:
This will allow you to set a Samba-specific password for sambauser
.
After setting the password, you need to enable the user in Samba:
If you have enabled the UFW firewall across the organization then you might need to configure the ufw to access the smb
If you want to allow samba connections from specific IPs or network then we can do it using the following commands :
You can configure Samba to authenticate against an LDAP directory for user management. Make sure you have an LDAP server set up before proceeding.
Install necessary packages:
Configure PAM to use LDAP: Edit the /etc/nsswitch.conf
file to ensure that the system checks the LDAP server for user and group information.
In /etc/nsswitch.conf
, modify the following lines to include ldap
:
Configure /etc/pam.d/common-session
to use LDAP for authentication: Ensure this line is present:
Configure the Samba LDAP authentication: Edit the /etc/samba/smb.conf
file and include the following:
Replace dc=example,dc=com
with the correct base DN for your LDAP directory.
After configuring the shares and LDAP authentication, restart the Samba service to apply the changes: