How to Share Files Over Samba on Arch Linux
Categories:
5 minute read
Samba is a powerful open-source implementation of the SMB/CIFS networking protocol, which allows file and printer sharing between computers running Windows and Unix-like systems such as Linux. On Arch Linux, configuring Samba is straightforward once you understand the basic components and steps. In this guide, we’ll walk through how to install, configure, and secure Samba for file sharing on Arch Linux.
1. Introduction to Samba
Samba is a suite of tools that enables Unix-based systems to interact with Windows systems in a networked environment. It allows for:
- File sharing between Linux and Windows machines
- Sharing printers across a network
- Acting as a domain controller (optional)
- Authentication and access control using user accounts
Arch Linux doesn’t come with Samba pre-installed, so you’ll need to install and configure it manually.
2. Installing Samba on Arch Linux
Begin by installing the samba
package from the official repositories.
sudo pacman -S samba
This installs the Samba server (smbd
), the NetBIOS name server (nmbd
), and associated tools.
To verify the installation, check the version:
smbd --version
3. Creating a Shared Directory
You can share any directory over the network. For this example, we’ll create a directory called shared
under /srv
.
sudo mkdir -p /srv/samba/shared
sudo chown nobody:nogroup /srv/samba/shared
sudo chmod 0775 /srv/samba/shared
Explanation:
nobody:nogroup
ensures the directory can be accessed without a dedicated user.0775
gives read/write access to the owner and group, and read/execute to others.
You can tailor permissions based on your needs.
4. Configuring the Samba Server
Samba uses a configuration file located at /etc/samba/smb.conf
. Start with a backup:
sudo cp /etc/samba/smb.conf.default /etc/samba/smb.conf
Then open the file with your preferred text editor:
sudo nano /etc/samba/smb.conf
Here’s a minimal example to share the shared
directory with guest access:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = archlinux
security = user
map to guest = Bad User
dns proxy = no
[Shared]
path = /srv/samba/shared
browsable = yes
writable = yes
guest ok = yes
read only = no
create mask = 0664
directory mask = 0775
Explanation:
workgroup
should match the workgroup of your Windows machines.security = user
allows user-based authentication.guest ok = yes
allows unauthenticated access (you can disable this for more security).
Save and exit.
5. Creating Samba Users
If you want to restrict access to authenticated users (recommended for private networks), you’ll need to create Samba users.
Step 1: Create a system user (if not already present)
sudo useradd -M -d /srv/samba/shared -s /usr/bin/nologin sambauser
sudo passwd sambauser
Step 2: Add the user to Samba’s password database
sudo smbpasswd -a sambauser
Then enable the user:
sudo smbpasswd -e sambauser
Make sure the shared directory is owned by this user if you disable guest access:
sudo chown sambauser:sambauser /srv/samba/shared
Update your smb.conf
file accordingly:
[Shared]
path = /srv/samba/shared
browsable = yes
writable = yes
valid users = sambauser
read only = no
6. Starting and Enabling the Samba Services
Samba uses two main services:
smbd
: Handles file sharingnmbd
: Handles NetBIOS name resolution (optional but useful)
Enable and start the services:
sudo systemctl enable --now smb.service
sudo systemctl enable --now nmb.service
Check the status:
systemctl status smb.service
systemctl status nmb.service
7. Adjusting the Firewall
If you use ufw
, open the required ports:
sudo ufw allow 'Samba'
Alternatively, with iptables
:
sudo iptables -A INPUT -p tcp -m multiport --dports 137,138,139,445 -j ACCEPT
sudo iptables -A INPUT -p udp -m multiport --dports 137,138,139,445 -j ACCEPT
Make sure to persist the rules if you use iptables
.
8. Accessing the Samba Share
From Linux
You can access Samba shares using smbclient
or mount them directly:
Install the client tools (if not already installed):
sudo pacman -S smbclient gvfs-smb
Then access:
smbclient //archlinux/Shared -U sambauser
Or mount using mount
:
sudo mount -t cifs //archlinux/Shared /mnt -o username=sambauser
From Windows
- Open File Explorer.
- In the address bar, enter:
\\archlinux\Shared
- Enter credentials if required.
Make sure the hostname archlinux
resolves correctly (use IP address if necessary).
9. Securing Your Samba Shares
Security is essential when sharing files. Here are a few tips:
1. Disable Guest Access
Avoid guest ok = yes
unless absolutely necessary. This prevents unauthorized access.
2. Use Firewall and VPNs
Restrict Samba access to known IPs or networks using firewall rules. Never expose Samba to the public internet directly.
3. Use Strong Passwords
Always set strong passwords for Samba users.
4. Audit and Monitor
Enable logging in smb.conf
:
log file = /var/log/samba/smbd.log
max log size = 1000
Check logs periodically for suspicious activity.
5. Regular Updates
Keep your system and Samba package updated:
sudo pacman -Syu
10. Conclusion
Setting up Samba on Arch Linux gives you a versatile and powerful file sharing solution that works across platforms. Whether you’re building a home media server, setting up a workgroup file share, or simply want to access Linux files from Windows, Samba makes it all possible.
While the default setup is relatively simple, it’s crucial to tailor your configuration for security, especially if your Samba server is part of a larger or sensitive network. You can further expand the setup with advanced options like access control lists (ACLs), encrypted connections, or integration with LDAP/Active Directory.
By following the steps in this guide, you now have a functioning Samba file server on your Arch Linux system.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.