Samba, also known as “Server Message Block,” is a protocol that provides file and print services between clients across various operating systems. Samba allows us to access and use files, printers, and other commonly shared resources on a local intranet. It can be run on Unix/Linux-based platforms and communicate with Windows clients.
This tutorial will show you how to install and configure the Samba server on Arch Linux.
Step 1 – Configure Repository
By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:
nano /etc/pacman.d/mirrorlist
Remove all lines and add the following lines:
## Score: 0.7, United States Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.8, United States Server = http://lug.mtu.edu/archlinux/$repo/os/$arch Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch ## Score: 0.9, United Kingdom Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch ## Score: 1.5, United Kingdom Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch ## Score: 6.6, United States Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch ## Score: 6.7, United States Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch ## Score: 6.8, United States Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch ## Score: 7.1, India Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch ## Score: 10.1, United States Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch
Save and close the file, then update all the package indexes with the following command:
pacman -Syu
Step 2 – Install Samba Server
The Samba server package is included in the Arch Linux default repository by default. You can install it easily with the following command.
pacman -S samba smbclient
After installing the Samba server, you can verify the Samba version using the following command.
smbd --version
You should see the following output.
Version 4.17.4
Step 3 – Create a Public Share in Samba
This section will show you how to create a public share in Samba. Anyone can access the public share without providing a username and password.
First, create files and directories for the public share with the following command.
mkdir -p /samba/public touch /samba/public/public1 touch /samba/public/public2
Next, set proper ownership to the public share directory.
chown -R nobody:nobody /samba
Next, create a Samba configuration file and define your public share:
nano /etc/samba/smb.conf
Add the following configuration:
[Public] comment = public share path = /samba/public browseable = yes writable = yes guest ok = yes
Save and close the file, then restart smb and NMB services to apply the changes.
systemctl start smb nmb
You can also verify the Samba configuration file using the following command.
testparm
You will get the following output.
# Global parameters [global] idmap config * : backend = tdb [Public] comment = public share guest ok = Yes path = /samba/public read only = No
Step 4 – Create a Private Share in Samba
This section will show you how to create a private share in Samba. A private share is password protected, so the user must provide a username and password to access the private share.
First, create a directory and files for the private share.
mkdir -p /samba/private touch /samba/private/private1 touch /samba/private/private2
Next, create a user for the private share with the following command:
useradd smbuser smbpasswd -a smbuser
Set a password as shown below:
New SMB password: Retype new SMB password: Added user smbuser.
Next, edit the Samba configuration file and define your private share.
nano /etc/samba/smb.conf
Add the following configuration:
[Private] comment = private share path = /samba/private browseable = yes guest ok = no writable = yes valid users = smbuser
Save and close the file, then restart SMB and nmb services to apply the changes.
systemctl restart smb nmb
Step 5 – Verify Public and Private Share
You must install the Samba client package on the remote system to verify the Samba share. You can install it with the following command.
pacman -S smbclient
Next, verify all Samba shares using the following command.
smbclient -L samba-server-ip
You will be asked to provide the password:
Password for [WORKGROUP\root]:
Just press the Enter key. You should see both public and private shares in the following output.
Anonymous login successful Sharename Type Comment --------- ---- ------- Public Disk public share Private Disk private share IPC$ IPC IPC Service (Samba 4.17.4) SMB1 disabled -- no workgroup available
To access the private share, run the following command.
smbclient //samba-ip-address/private -U smbuser
You will be asked to provide a password for smbuser:
Password for [WORKGROUP\smbuser]:
Provide your password, then press the Enter key. You will get into the Samba shell:
Try "help" to get a list of possible commands. smb: \>
List your files and directories inside the private share with the following command.
smb: \> ls
Output.
. D 0 Wed Jan 4 10:47:34 2023 .. D 0 Wed Jan 4 10:47:24 2023 private2 N 0 Wed Jan 4 10:47:34 2023 private1 N 0 Wed Jan 4 10:47:29 2023 51473020 blocks of size 1024. 46301492 blocks available
Now, exit from the Samba shell with the following command.
smb: \> exit
You can access the public share with the following command.
smbclient //samba-ip-address/public
You will be asked to provide a password.
Password for [WORKGROUP\root]:
Just press the Enter key to connect to Samba.
Anonymous login successful Try "help" to get a list of possible commands.
Now, verify all files and directories inside the public share.
smb: \> ls
You will get the following output.
. D 0 Wed Jan 4 10:45:29 2023 .. D 0 Wed Jan 4 10:47:24 2023 public2 N 0 Wed Jan 4 10:45:29 2023 public1 N 0 Wed Jan 4 10:45:24 2023 51473020 blocks of size 1024. 46301492 blocks available smb: \>
Conclusion
This tutorial explained how to install the Samba server on Arch Linux. We also explained how to create a public and private share in Samba. You can now deploy the Samba server in your organization to share files and printers. You can try out a Samba server on dedicated server hosting from Atlantic.Net!