Samba is the server application that implements client terminal access to folders, printers and disks through the SMB/CIFS protocol.
To install and configure Samba server for Ubuntu, follow these steps.
Update the repository information and install any updates:
sudo apt update
sudo apt full-upgrade
Install Samba:
sudo apt install -y samba samba-client smbclient cifs-utils
Make a copy of the configuration file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf_sample
Create a folder to share between users:
sudo mkdir /media/samba
sudo mkdir /media/samba/public
Grant the necessary access rights to the folder:
sudo chmod -R 0755 /media/samba/public
Create a directory for a given number of users:
mkdir /media/samba/private
Create the user group for samba:
sudo groupadd smbgrp
Add the Samba users you need:
sudo useradd user1
Repeat for each user
Add the created users to the group:
sudo usermod -aG smbgrp user1
Repeat for each user
Change the group that owns the limited users directory:
chgrp smbgrp /media/samba/private
Create a password for each added user:
sudo smbpasswd -a user1
Repeat for each user
Edit the previously backed up samba configuration file with nano:
nano /etc/samba/smb.conf
Delete all lines from the file.
Insert the following:
[global]
workgroup = WORKGROUP
security = user
map to guest = bad user
wins support =
no dns proxy = no
[public]
path = /media/samba/public
guest ok = yes
force user = nobody
browsable = yes
writable = yes
[private]
path = /media/samba/private
valid users = @smbgrp
guest ok = no
browsable = yes
writable = yes
Save with Ctrl + X.
global — general Samba server settings
public and private — description of configuration directories.
global has five parameters:
workgroup — workgroup. WORKGROUP is specified as the default group.
ONLINE — The value user means authorization by the username/password pair;
map for guests — defines how requests are processed. ;
wins support — • enable or disable WINS support;
proxy dns — ability to send requests to a DNS.
Directory settings
path — full path to the directory on your hard drive;
guest ok — ability to access the folder without a password (guest);
browsable — whether to display the folder on the server
force user — the user who is working with the folder. To increase server security, "nobody" is usually used.
write — yes allows the user to perform actions on files inside the folder
valid users — list of users who have access to the folder.
If there are multiple users, their names are separated by commas. If access is required for users belonging to a group, the “at” symbol (@) is placed before the group name.