Let’s look at the process of installing Samba software on a cloud server with the Ubuntu 22.04 operating system. This guide is also suitable for installing Samba on Debian. Let’s start with a brief description of this software.
Samba is a software package developed to provide compatibility and interaction between UNIX-like systems and Windows. The software has been distributed under a free license for over 30 years. Samba ensures seamless integration of servers and PCs running UNIX into an AD (Active Directory) system. This software can be used as a controller and as a standard component of a domain. Thus, users can flexibly configure cloud file storages. Samba provides extensive functionality for managing file and database access rights by assigning specific user groups.
Go to the control panel and create a new server.
Select the Ubuntu 22.04 image and then the minimum server configuration.
After creating the server, connect to it via SSH, and you can begin configuration.
This is simple — enter the command:
sudo useradd -p new_server_pass new_server_user
Instead of new_server_pass
and new_server_user
, you can use any password and any username. Enter your own data instead of the example ones. Note that we immediately set the password, which was possible thanks to the -p
command.
For convenience, we have broken the installation process into separate steps.
To start the installation process, use the following command:
sudo apt install samba -y
Now you need to remember the system name of the service. In most cases, it is smbd
. Therefore, if you want to call the service, use this name.
First, let’s configure autostart, which is done with the command:
sudo systemctl enable smbd
Now start it using the familiar command:
sudo systemctl start smbd
Then check the system status using:
sudo systemctl status smbd
To stop Samba, use:
sudo systemctl stop smbd
To restart the service, enter:
sudo systemctl restart smbd
If you want Samba to no longer start automatically, use the command:
sudo systemctl disable smbd
The reload
command is used to refresh the configuration.
The following command will forcibly open port 445, as well as 137–139. To allow them in the ufw
firewall, use:
sudo ufw allow Samba
Suppose you have some remote server located outside your cloud. Network security rules require that you never open direct access to it through its IP. You can only do this through a tunnel, which is already set up. Typically, servers with granted access have the address 10.8.0.1
, and this is the address we will use further.
To share data and grant anonymous access to it, first open the configuration file. It is located here: /etc/samba/smb.conf
. We recommend making a backup of the clean file — this will help you quickly restore the original program state without needing to reinstall. Now remove all comments, leaving only the code, and enter the command testparm
to ensure the program works properly. In the shared folder settings, enter the following parameters:
[share]
comment = share
path = /data/public_share
public = yes
writable = yes
read only = no
guest ok = yes
Also, make sure that the following four fields (mask and mode) have matching numeric values (for example, 0777).
Regarding the specific lines:
[share]
— the name of the shared folder, which will be visible to everyone connecting to your server;comment
— a comment that can be anything;path
— the path to the data storage folder;public
— gives permission for public access: if you do not want users to view the folder contents, set this to no
;writable
— determines whether data can be written to the folder;read only
— specifies that the folder is read-only: to allow users to create new files, set it to no
;guest ok
— determines whether guests can access the folder.Thus, the folder name and path may differ depending on what values you specify for the shared folder. The comment can also be anything, and for the last four parameters, values are set as yes
or no
. Now restart the program and check if you can connect to the server from Windows.
To create access by login and password, you first need to create a new directory and configure permissions. In the configuration file, set all parameters to no
(see above), except writable
: in this line, the value should be yes
, meaning that writing in the folder should be enabled.
Use the mkdir
command to create a new directory, then create a user with useradd someone
(where someone
can be any username) and set a password for them with the command passwd
. For example:
passwd something
Now, with the command below, add the new user and try to log in: if everything is configured correctly, you will have access to the folder.
sudo smbpasswd -a someone
Configuring group access is necessary when you need to create restricted access for specific user groups. In smb.conf
, after the line guest ok, additionally specify the following lines (all usernames here are generated simply for example):
valid users = admin, mary_smith, jane_jameson, maria ortega, nathalie_brown
write list = admin, nathalie_brown
In the valid users
line, list the users who are granted access to the directory. And in the write list
, list those who can modify data in the folder.
In addition, after the force directory mode
line, add another line with the following value:
inherit owner = yes
This enables inheritance of created objects. Now save the settings and restart the service, after which the new settings should take effect.
For quick connection to Samba from Windows, press Ctrl+E and enter the path. Note that you need to use \\
to indicate the network path to the resource. And to avoid reconnecting to the server each time, you can choose the option to connect the resource as a drive, if your security policy allows it. In the new window, specify the drive letter and fill in the required data.
For connecting to Samba from Linux, you use the cifs
utilities, which are installed with the command:
sudo apt install cifs-utils -y
Next, the resource is mounted and connected. This is done with:
sudo mount.cifs //10.8.0.1/our_share /share
The path and resource name can be anything. You can also perform automatic mounting using the configuration file fstab
with its own settings.
This operation is needed to avoid accidental permanent deletion of files. For this, create the following directory:
[Recycle]
comment = Trash for temporary file storage
path = /directory/recycle
public = yes
browseable = yes
writable = yes
vfs objects = recycle
recycle:repository = .recycle/%U
recycle:keeptree = Yes
recycle:touch = Yes
recycle:versions = Yes
recycle:maxsize = 0
recycle:exclude = *.tmp, ~$*
recycle:exclude_dir = /tmp
Now, let’s review line by line what these parameters mean:
vfs objects = recycle
— indicates use of the corresponding subsystem;repository
— the path for storing deleted data;keeptree
— whether to keep the directory tree after deletion;touch
— whether to change the timestamps of files when they are moved to the trash;versions
— whether to assign a version number if files with identical names are deleted;maxsize
— the maximum size of a file placed in the trash. A value of 0 disables limits;exclude
— which file types to exclude;exclude_dir
— which directories to exclude.That’s it — now you know how to install Samba on an Ubuntu cloud server and configure it for your own needs.