With Samba software package, the sharing network between a drive and printers across different operating systems is made possible and easily executed.
This article will guide you in the installation of Samba as well as configuring it via its configuration file.
Here at Ibmi Media, as part of our Server Management Services, we regularly help customers to do installation tasks on their Linux Servers.
In this context, we shall look into how to install Samba on Ubuntu.
Steps to install Samba on Ubuntu 18.04?
As earlier stated, with Samba sharing of devices between different Operating system is possible in a convenient way. In this case, we shall look into how install Samba on Ubuntu to use it as a file storage medium to make it easily to access from a Windows computer.
To get started, update the system packages when you log into your Server via SSH with the command below;
apt-get update && apt-get -y upgrade
After updating the system, continue with the installation of Samba on Ubuntu by using the command below;
apt-get install samba
This will install Samba.
How to configure Samba on Ubuntu?
To configure the installed Samba software, you can do it via its configuration file which is located at the /etc/samba directory. You can make a backup of this file by rename the file to make a duplicate of it by creating a new file with a different name but with the same contents as per the configuration file. This is important for security reasons just in case you mess the configuration up.
You can create a new configuration file with the command below;
/etc/samba# touch smb.conf
Next, create a "smbusers" file which stores the username and password of people accessing the file server. You will see that the password is encrypted with the directive "= yes" in samba configuration file (smb.conf). Use the command below to create the "smbusers" file;
/etc/samba# touch smbusers
This will create a folder which can be shared on the network. Ensure that the permission to allow users to read, write and modify it is set on the folder.
Use the command below to set the necessary permission;
/etc/samba# mkdir /opt/WorkingTestShare
/etc/samba# chmod 0777 /opt/WorkingTestShare
Next open up the configuration file (smb.conf) which consists of different sections such as the [global], [Documents], [Files], [Video] and so on.
How to configure Samba via its configuration file?
Samba configuration file is made up of different settings. To begin, we will implement the main section and give it a name as per our server requirement. You can declare it as seen below;
server string = Test Fileserver Samba
Next, look out for a workgroup which exists on a Windows network. Its default name is "WORKGROUP" as seen below;
workgroup = WORKGROUP
Now, you can set the server role for the file. Do as follows;
server role = standalone server
Furthermore, you can look out for the "configure authorization" settings and enable it to enable users to be able to access the file server, download files, read, delete, modify. In additional, users with a username and password will be able to access it. To implement this , use "user" declaration just as seen below;
security = user
Next, specify the database file for the user. This file helps to store users who have access to the system. Implement this with the following directive;
smb passwd file = /etc/samba/smbusers
You can improve security by enabling the "force enable password encryption" setting to reduce external attacks. Use the directive below;
encrypt passwords = yes
To further enhance security, you can block guest access with the directive;
map to guest = bad user
Next step is to specify where the logs for the application will be stored. the following directive can be used to implement this;
logfile = /var/log/samba/log.%m
Another important aspect of this configuration is the comment capability. The comment helps to give more insight about a folder when you hover on it. This can be implemented below;
comment = Our Working Test Share
The path to the folder we will work with can also be indicated with the directive below;
path = /opt/WorkingTestShare
To make the folder visible, it is important to enable the browseable setting and also you can make the shared folder writeable via the following commands below;
browseable = yes
writeable = yes
To determine the permission level assigned to files which will be uploaded to the shared folder and its directories, use the directive below;
create mask = 0775
directory mask = 0775
After making these changes, you can save Samba configuration file and exit with the "ctrl + x" keyboard option and enter "y" to continue.
After saving the file, perform a restart of the service with the command below;
service smbd restart
For ease of use, add the service to systemctl startup configuration with the following command;
/etc/samba# systemctl enable smbd
To verify if Samba is running, use the command below;
service smbd status
You will see the shared folder in a networked environment. To locate the server IP address, use the "ifconfig" command.
Connection for Windows using Samba
In order to achieve a successful connection to a share resource of folder on Windows, go to the network environment with the Server IP address.
A username and password needs to be created locally on the file server which must be saved in the smbusers file which was previously created.
use the command below to create a username and password for Samba connection;
useradd -c "samba user n1" -s /sbin/nologin user2
"-s /sbin/nologin user2" as per the command above signifies that the user cannot log into the server by itself. This is a security measure place on the service.
To set the password, use the command below;
smbpasswd -a user2
Now you can log into the file system and once successful, proceed with the creation of the folder and files.
To add all users to the same group, first create a new group with the command below;
Lets say, we have 2 users created with name "user2" and "user3", we can then set the default group for both users with the commands below;
usermod -g group1 user2
usermod -g group1 user3
To effect changes, perform and restart of the Samba service with the command below;
service smbd restart
To change ownership for all the files and the folder, use the command below;
chown -R user1:group1 /opt/WorkingTestShare
What this implies is that user3 will be able to edit files in the group1 folder just like user2. This method can also be applied to other users.
The settings also allows users to be able to download and modify files on the shared folder.