Back to Homepage
Saturday 22 February 2025
24

How to Install Samba on Ubuntu Server 22.04

1. Update the System

It is important to ensure that all system packages are updated before proceeding with the installation. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

2. Install Samba

Installing Samba on Ubuntu is easy thanks to the packages available in the official repositories. Run the following command to install Samba:

sudo apt install samba

3. Configure Samba

Once installed, we need to configure Samba to share files and directories. The main Samba configuration file is located at /etc/samba/smb.conf.

Edit the Configuration File

Open the configuration file with your favorite text editor, for example, nano:

sudo nano /etc/samba/smb.conf

Inside this file, you can define the sections and parameters needed to share directories. Below is a basic configuration example for sharing a directory:

[global]
   workgroup = WORKGROUP
   server string = %h server (Samba, Ubuntu)
   dns proxy = no

[shared]
   path = /srv/samba/shared
   browsable = yes
   writable = yes
   guest ok = yes
   read only = no
   create mask = 0755

In this example:

  • The [global] section contains general settings, such as the workgroup name (workgroup = WORKGROUP) and the server name (server string = %h server (Samba, Ubuntu)).
  • The [shared] section defines a shared resource named "shared" located in the /srv/samba/shared directory. This resource is browsable (browsable = yes), writable (writable = yes), and allows guest access (guest ok = yes).

Create the Shared Directory and Adjust Permissions

We need to create the directory to be shared and adjust permissions so that Samba can access it:

sudo mkdir -p /srv/samba/shared
sudo chown -R nobody:nogroup /srv/samba/shared
sudo chmod -R 0755 /srv/samba/shared

4. Restart the Samba Service

After making changes to the configuration, we need to restart the Samba service for the changes to take effect:

sudo systemctl restart smbd
sudo systemctl restart nmbd

5. Check the Status of the Samba Service

To ensure that the Samba service is running correctly, check its status:

sudo systemctl status smbd
sudo systemctl status nmbd

6. Configure the Firewall

If you have a firewall configured on your server, you need to allow Samba traffic. You can do this using ufw (Uncomplicated Firewall) with the following command:

sudo ufw allow samba

7. Access the Shared Resource from Windows

To access the shared resource from a Windows machine, open File Explorer and enter the following in the address bar:

\\<server_ip_address>\shared

where <server_ip_address> is the IP address of your Ubuntu server.

8. Add Users to Samba (Optional)

If you prefer to enable authentication instead of allowing anonymous access, you can create Samba users with the following command:

sudo smbpasswd -a username

This command will create a Samba user based on an existing system user. Make sure the Ubuntu user already exists before running this command.

Share:
Created by:
Author photo

Jorge García

Fullstack developer