Skip to content

Linux »

Samba - Sharing Files in a Network

Samba is a free and open-source re-implementation of the SMB/CIFS network file sharing protocol that allows end users to access files, printers, and other shared resources.

Last update: 2022-06-22

Table of Content


Samba is available from the official Ubuntu repositories. To install it on Ubuntu system follow the steps below:

  1. Start by updating the apt packages index:

    sudo apt update
  2. Install the Samba package with the following command:

    sudo apt install -y samba
  3. Once the installation is completed, the Samba service will start automatically. To check whether the Samba server is running, type:

    sudo systemctl status smbd
    smbd.service - Samba SMB Daemon
    Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
    Active: active (running) since Mon 2021-07-12 15:30:57 +07; 1min 41s ago
        Docs: man:smbd(8)
    Main PID: 4059 (smbd)
    Status: "smbd: ready to serve connections..."
        Tasks: 4 (limit: 2329)
    CGroup: /system.slice/smbd.service
            ├─4059 /usr/sbin/smbd --foreground --no-process-group
            ├─4061 /usr/sbin/smbd --foreground --no-process-group
            ├─4062 /usr/sbin/smbd --foreground --no-process-group
            └─4064 /usr/sbin/smbd --foreground --no-process-group
    Jul 12 15:30:57 ubuntu18 systemd[1]: Starting Samba SMB Daemon...
    Jul 12 15:30:57 ubuntu18 systemd[1]: Started Samba SMB Daemon.

Add a user#

Samba has its own user management system. However, any user existing on the samba user list must also exist within/etc/passwd file. Use the smbpasswd command to add a user to Samba user list:

sudo smbpasswd -a $USER


Before making changes to the Samba configuration file, create a backup for future reference purposes:

sudo cp /etc/samba/smb.conf{,.backup}

Edit the Samba configuration file

sudo nano /etc/samba/smb.conf

The default configuration file that ships with the Samba package is configured for standalone Samba server. Open the file and make sure server role is set to standalone server.

# 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

Uncomment the [home] section, then edit its options as below:

   comment = Home Directories
   browseable = yes
   read only = no
   create mask = 0700
   directory mask = 0700
   valid users = %S

Use mask 0775 to enable execution permission.

Save the file, then test the parameters by running the utility testparm to see the configs:

Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK.

Press enter to see a dump of your service definitions

# Global parameters
    dns proxy = No
    log file = /var/log/samba/log.%m
    map to guest = Bad User
    max log size = 1000
    obey pam restrictions = Yes
    pam password change = Yes
    panic action = /usr/share/samba/panic-action %d
    passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
    passwd program = /usr/bin/passwd %u
    server role = standalone server
    server string = %h server (Samba, Ubuntu)
    syslog = 0
    unix password sync = Yes
    usershare allow guests = Yes
    idmap config * : backend = tdb

    browseable = No
    comment = Home Directories
    create mask = 0700
    directory mask = 0700
    read only = No
    valid users = %S

    path = /mnt/work
    comment = Workspace
    create mask = 0700
    directory mask = 0700
    read only = No

Then restart the service:

sudo service smbd restart

Finally, connect to the Samba Server from another computer with username and password set in above steps. The path to the Samba server can be located by IP Address, e.g. \\\<username> or by a computer name, e.g. \\ubuntu\<username>.

Quick clear the config file after making a backup:

sudo bash -c 'echo "" > /etc/samba/smb.conf'