Samba is one of the many ways to share files and directories across a network on Linux. With a Samba share up and running, any machine within your LAN can access the contents of the shared directory—so long as the user has access. Samba is also one of the easiest to set up for this task.
In today’s tutorial, we’ll go through the process of installing and setting up a Samba share.
To install Samba open a terminal and run the following command.
sudo apt install samba smbclient cifs-utils --no-install--recommends -y
Configuring a Samba share
Next, Samba shares will be configured in /etc/samba/smb.conf, so open that file with the command.
sudo nano /etc/samba/smb.conf
The first option we’ll configure is the workgroup name. Look for the line:
Change that to:
workgroup = WORKGROUPNAME
Where WORKGROUPNAME is the name of the workgroup or NT-domain your Samba server will exist within. Then create either a directory or take note of the directory path you’re going to set as the share. Ensure that the directory is accessible to the user you’re entering in the configuration file. In this example, we created the directory /smb_share.
To configure the share, add the following to the bottom of the file.
[DATA] path = /directory valid users = @user browsable = yes writable = no read only = yes
You can adjust the values above to your needs.
The configuration is straightforward:
- [DATA] the visible name of the share
- valid users = a group that can access the share.
- path – the exact path of the share
- browsable – makes the share visible to the network
- writable – makes the share writable to authenticated users
- read only – sets the read-only option to no
Save and close the file
Now reboot for the service to load correctly. To ensure that the service has started, run the following command.
rc-status| grep smbd
Add a user to Samba
You must also add Samba users; otherwise, they won’t authenticate.
The first thing we have to do is add the user to Samba with the command.
sudo smbpasswd -a $USER
You’ll be prompted to type and verify a password for the user.
Next, enable the user with the command.
sudo smbpasswd -e $USER
Connect to the new share
To connect to a share, open Index and right-click to open the context menu, then select Go to and enter the server’s address and the path to the directory. For example, if the server IP is 10.0.2.15 and the share is called DATA, the address would like this.
That’s it; you can start working with the files contained within.
When accessing a Samba share in Index, the contents may not load immediately, requiring the user to go back and forward without closing the application; otherwise, the user will need to authenticate again. This behavior is a bug, and we’ll fix it.