DEV Community

Shakhzhakhan Maxudbek
Shakhzhakhan Maxudbek

Posted on • Originally published at args.tech

How to share folder by network via Samba protocol in Linux machine

This tutorial provide how to configure directory as network share on Linux machine. After configuration finished, you may exchange files between any operating systems (Windows, MacOS and Linux) by network. Samba will help us with this. So, what is Samba? View official page.

Samba is the standard Windows interoperability suite of programs for Linux and Unix.
Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member.
Samba is a software package that gives network administrators flexibility and freedom in terms of setup, configuration, and choice of systems and equipment.
Enter fullscreen mode Exit fullscreen mode

Installing Samba in Debian based distros:

sudo apt install samba -y
Enter fullscreen mode Exit fullscreen mode

Most users are running packages shipped with their distribution or from 3rd parties, such as SerNet (Samba+/Enterprise). However, in some situations you may decide to compile Samba yourself, for reasons such as:

  • outdated packages are shipped with your distribution;
  • no packages are available for your distribution or OS;
  • you want to apply a patch from a developer to fix a problem before a new version is released.

Create folder which must be shared:

mkdir /home/user/share
Enter fullscreen mode Exit fullscreen mode

Add configuration, which tell to Samba service about share name, path, pubic status, writable or not in bottom of /etc/samba/smb.conf file:

[share]
path = /home/user/share/
public = yes
writable = yes
Enter fullscreen mode Exit fullscreen mode

Attention! This configuration means that your folder is public and has access without authentication.

If you want authenticate users with password add following line in /etc/samba/smb.conf file:

valid users = your_user
Enter fullscreen mode Exit fullscreen mode

and change public value to no.

Create new user for Samba service:

sudo smbpasswd -a your_user
Enter fullscreen mode Exit fullscreen mode

And enter new password.

Then you need start samba daemon:

sudo systemctl start smbd
Enter fullscreen mode Exit fullscreen mode

And (if you need) enable it in autorun:

sudo systemctl enable smbd
Enter fullscreen mode Exit fullscreen mode

If you use UFW firewall you need to open 139 and 445 ports:

sudo ufw allow 139
sudo ufw allow 445
Enter fullscreen mode Exit fullscreen mode

Are my posts is helpful? You may support me on Patreon.

Top comments (0)