Samba is a software package that allows us to access a shared network drive and printers across various operating systems. Install of Samba on Ubuntu also involve a step to tweak the settings in the Samba configuration file.
As a part of our Server Management Services, we help our Customers with software installations regularly.
Let us today discuss the steps to install Samba in Ubuntu.
How to install samba on Ubuntu?
Samba allows us to access a shared device across various Operating systems. Today, let us discuss the steps to set up an Ubuntu server as a file storage platform that we can easily access from a Windows computer.
The initial step here is to update the packages available for installation with the command below:
root@host:~# apt-get update && apt-get -y upgrade
We can now begin the Samba installation on the Ubuntu server with the command below:
root@host:~# apt-get install samba
Samba Configuration
Now that we have installed Samba, let us move on to customize its configuration.
The configuration file for Samba by default will be in the location /etc/samba. Before making any changes to the configuration file, it is a good idea to backup or rename the configuration file smb.conf in this location.
After renaming the configuration file, we need to create a new one.
root@host:~# /etc/samba# touch smb.conf
Now, we will create a “smbusers” file. This file stores the username and password of the people who will be accessing the file server. The encrypt passwords = yes‘ in the smb.conf file ensures to encrypt this information.
root@host:~# /etc/samba# touch smbusers
Then, we will create a folder that we will share on the network and must apply a permission set that allows our users to read, write, and modify it.
/etc/samba# mkdir /opt/FirstTestShare
/etc/samba# chmod 0777 /opt/FirstTestShare
Now we will open and configure the smb.conf using a text editor.
The configuration file consists of several sections. [global] is the central part. We can add additional sections like [Documents], [Files], and [Video] as per our need.
Settings in Samba configuration file
Let us now look at the different settings in the Samba configuration file. Initially, we will set up the main section and provide a name for our server.
server string = Test Fileserver Samba
Secondly, we will identify a workgroup that exists on a Windows network. The default name for a workgroup is WORKGROUP.
workgroup = WORKGROUP
Thirdly, let us set the file server role. Samba has multiple functions, but today, we will be using it as a simple file server.
server role = standalone server
Further, we will review the “configure authorization” settings. We need this option enabled to allow access to the file server, download files, read, modify and delete, only for those users who have a username and password added. Use the value user – authorization by login and password.
security = user
After this, we need to specify the user database file. This file identifies and stores the users we have provided access for.
smb passwd file = /etc/samba/smbusers
Next, we should enable the “force enable password encryption” setting. This setting is essential for security concerns and reduces the chances of attacks.
encrypt passwords = yes
Additionally, we can also forbid guest access to the share. Using this setting, we can prohibit guest user logins and authorization attempts.
map to guest = bad user
Now, we can determine how and where the application logs will be stored. A higher the number (from 0 -7), indicates a more detailed level of logging.
Normally, debugging purposes require higher logging levels.
logfile = /var/log/samba/log.%m
The next setting we will look at is a comment. This comment will be the tooltip value that will be displayed when we hover over the folder.
comment = Our First Test Share
It is also essential to indicate the path of our folder that we will share.
path = /opt/FirstTestShare
Enabling the browseable setting makes the folder visible. Further, the writeable bit allows users to write to the shared folder.
browseable = yes
writeable = yes
Finally, we can determine the permissions level that will be assigned to files uploaded to the shared folder and for directories.
create mask = 0775
directory mask = 0775
Now that we have finished with the configuration file save it using the “ctrl + x” option. After saving the configuration file, we need to restart the service.
service smbd restart
To add the service to the systemctl startup configuration, follow the command below
root@host:~#/etc/samba# systemctl enable smbd
Next, we can verify if Samba is up and running.
$ service smbd status
Now we can see our shared folder in a networked environment. We will locate our IP address by using the ifconfig command.
Windows Connection
To connect to the share on Windows, we need to go to the network environment and enter our IP address.
Next, because we need to create the username and password, if we are not aware of them. Here we will set up a user locally on the file server and then save them to our previously created smbusers file.
useradd -c "samba user n1" -s /sbin/nologin user1
The “–s /sbin/nologin user1” means that the user will not be able to log into the server itself. This is a security measure.
smbpasswd -a user1
Now, we can go into the file system and try to log in. Once we can log in to the file server, we can create our folders and files as well as read other people’s files and folders.
Let us include all the users in the same group. We can accomplish this by creating a new group.
groupadd buh
Then set the default group for both user1 and user2.
usermod -g buh user1
usermod -g buh user2
We can now restart Samba to apply the new changes.
service smbd restart
Here, we can change the ownership settings for all the files and for the folder itself.
chown -R user1:buh /opt/FirstTestShare
Now, user2 will be able to edit files in the Buh folder, like user1. We can also accomplish this with other users as well.
Further, another essential aspect of these settings is that users can download and modify a file, then re-save it to the shared folder.
[Need any further assistance to install Samba on Ubuntu? – We’re available 24*7]
Conclusion
In short, Samba is a software package that allows us to access a shared network drive and printers across various operating systems. Today, we saw how our Support Engineers install Samba on Ubuntu.
0 Comments