Professional Documents
Culture Documents
Ubuntu 22.04
By Sumit Patel & Darshita Daga --- On Jul 19, 2023
Install Samba on Ubuntu 22.04 with our step-by-step tutorial. It enables file sharing and
networking between different operating systems.
Samba is a widely used open-source software suite that enables file sharing and
networking between different operating systems. It allows seamless communication
between Windows, Linux, and macOS systems, enabling them to share files, printers, and
other resources over a network.
With Samba, users can easily access files and resources from diverse platforms, fostering
collaboration and data exchange. It simplifies network administration by providing a
unified interface for managing access permissions and security settings. Samba is a
powerful tool for creating heterogeneous networks and enhancing connectivity among
devices and operating systems.
©ms_anna/1-2023_2024
1
2) Install Samba package using this:
3) After installation, the Samba service will be operative. To verify if the Samba server is
running or not, use the below command:
This output will appear to show that the Samba service is activated:
output
1) Presuming that UFW is being used to manage the firewall, open the ports by allowing
the ‘Samba’ profile:
©ms_anna/1-2023_2024
2
sudo cp /etc/samba/smb.conf{,.backup}
2) At this point, the default configuration file which comes alongside the Samba
package has been configured for a standalone Samba server. Open the file and ensure
that server role is set to standalone server by using this:
/etc/samba/smb.conf
...
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
server role = standalone server
...
3) By default, Samba operates on each and every interface. In case you desire to restrict
access to the Samba server only on the internal network then uncomment the following
two lines and specify the interfaces to bind to:
/etc/samba/smb.conf
...
# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
interfaces = 127.0.0.0/8 eth0
# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself. However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
bind interfaces only = yes
...
4) After completion, run the testparm utility to verify the Samba configuration file and
ensure that it's error-free. In case there are no syntax errors Loaded services file OK. will
appear.
©ms_anna/1-2023_2024
3
sudo systemctl restart smbd
2) Then make sure that group ownership is set to sambashare. While the Samba
installation, this group is created, and later you will add all Samba users here.
3) Samba utilizes Linux users and a group permission system. Although it has an
authentication mechanism of its own as well. One may create users through the
standard Linux useradd tool and later on set the password of the user
via smbpasswd utility.
4) Following step is to create a regular user that can access private file share and a single
administrative account with read/write permission to all shares on the Samba server.
• -M - do not create the user’s home directory, you will manually create this
directory.
• -d /samba/josh - set the user’s home directory to /samba/josh.
• -s /usr/sbin/nologin - disable shell access to this user.
• -G sambashare - add the user to the sambashare group.
Following this, create a user’s home directory and set the directory ownership to
user josh and group sambashare using this command:
©ms_anna/1-2023_2024
4
sudo mkdir /samba/josh
3) This next command would add the setgid bit to the /samba/josh directory and hence, the
files created recently in the directory will inherit the group of the parent directory. This
ensures that if a user creates a new file the file will have a group-owner of sambashare.
4) Then, josh user account is to be added to the Samba database and can be done by
setting the user password:
Once the command is run you would be prompted to put the user password.
Output
output
6) For creating another user, carry out the same process which you would for creating
the user josh.
Now, follow these steps to create a user and group sadmin. Each and every member of
this group has administrative permissions. In case, you desire to grant administrative
permissions to any other user, just add that user to the sadmin group.
8) The aforementioned command shall also create a group sadmin and add the user to
both sadmin and sambashare groups.
©ms_anna/1-2023_2024
5
9) The next step is to set the password and allow the user:
10) After this, you need to create the Users share directory:
11) Then you have to set directory ownership to the user sadmin and group sambashare by
using this command:
12) This directory can be accessed by each and every authenticated user. The
next chmod command provides write/read access to members of the sambashare group in
the /samba/users directory:
/etc/samba/smb.conf
[users]
path = /samba/users
browseable = yes
read only = no
force create mode = 0660
force directory mode = 2770
valid users = @sambashare @sadmin
[josh]
path = /samba/josh
browseable = no
read only = no
force create mode = 0660
force directory mode = 2770
valid users = josh @sadmin
©ms_anna/1-2023_2024
6
These options have the meanings given below:
• [users] and [josh] - The names of the shares to use when logging in.
• path - The path to the share.
• browseable - If the share is to be listed in the list of the available shares. By
setting to no, other users won't be able to see the share.
• read only - If the users specified in the valid users list can write to this share.
• force create mode - Sets the permissions for the files which are newly created.
• force directory mode - Sets the permissions for the newly created directories in this
share.
• valid users - A list of users and groups that are allowed to access the share.
In the next sections, we have discussed how to connect to a Samba share from Linux,
macOS, and Windows clients.
©ms_anna/1-2023_2024
7
smbclient //samba_hostname_or_server_ip/share_name -U username
4) For instance, in order to connect to a share named josh on a Samba server with an IP
address 192.168.121.118 as user josh, you need to use the command:
Output
6) After entering the password, you are into the Samba command-line interface.
Output
©ms_anna/1-2023_2024
8
5) For instance, for mounting a share titled josh on a Samba server along with the IP
address 192.168.121.118 as user josh to the /mnt/smbmount mount point, use the following
command:
6) Then, this will appear and you will enter the user password.
Output
1. Open “Finder”, choose the option “Go” and then click on “Connect To”.
2. Under “Connect To”, you must put the address of the Samba share in this
format: smb://samba_hostname_or_server_ip/sharename.
3. Then hit “Connect”.
4. Choose the “Registered User” option and then put the Samba username and
password and hit “Connect”.
5. The files on the Samba server will appear.
©ms_anna/1-2023_2024
9
Windows users can also connect to the Samba share from, both, the command line and
GUI. These are the steps to access the share utilizing the Windows File Explorer.
1. Open the "File Explorer" and on the left-panel right-click on “This PC”.
2. Find and select the option which says “Choose a custom network location” and
then hit “Next”.
3. In “Internet or network address”, put the address of the Samba share in this
format: \\samba_hostname_or_server_ip\sharename.
4. After hitting the option “Next” and you need to enter the login credentials.
5. Then, in the following window, one may type a custom name associated with the
network location. The Samba server will choose the default one.
6. Hit “Next” for moving the last screen on the connection setup wizard.
7. Finally, click on “Finish” then Samba server filed will appear.
Source: https://vegastack.com/tutorials/how-to-install-and-configure-samba-on-ubuntu-22-04/
©ms_anna/1-2023_2024
10