Storing various data such as photos and videos on a personal computer can gradually consume disk space. Additionally, sharing data within a household often requires manual file transfers using USB drives, which can be cumbersome.
Setting up a dedicated file-sharing server helps address these issues. A central file server allows storing data in one location, freeing up space on personal computers, and enabling seamless data sharing across multiple devices.
Samba is used as the file-sharing solution, facilitating interoperability among Linux, macOS, and Windows systems.
Installing Samba #
On the server, install Samba using the following command:
# Arch Linux
sudo pacman -S sambaCreating Samba Access Users #
Samba requires a corresponding Linux user to manage access. If necessary, create users using useradd. After that, register the users with Samba using the pdbedit command.
Example of registering existing Linux users (mako, sato, taka) for Samba access:
sudo pdbedit -a mako
sudo pdbedit -a sato
sudo pdbedit -a takaUsernames are shared with the Linux system, but passwords are managed separately.
Creating Directories for Samba #
A directory structure is set up to distinguish between personal directories and a shared directory for multiple users.
Creating the Samba Root Directory #
sudo mkdir -p /data/shareCreating Personal Directories #
Directories for individual users are created with appropriate ownership:
sudo mkdir /data/share/personal
sudo mkdir /data/share/personal/mako
sudo mkdir /data/share/personal/sato
sudo mkdir /data/share/personal/taka
sudo chown mako:mako /data/share/personal/mako
sudo chown sato:sato /data/share/personal/sato
sudo chown taka:taka /data/share/personal/takaCreating a Shared Directory #
A user group is created for shared access, and users are added to it:
sudo groupadd -g 2000 common
sudo gpasswd -a mako common
sudo gpasswd -a sato common
sudo gpasswd -a taka commonThe shared directory is created and assigned appropriate group ownership:
sudo mkdir /data/share/common
sudo chown :common /data/share/commonTo ensure all files inherit the correct group ownership, the setgid bit is set:
sudo chmod g+s /data/share/commonConfiguring Samba #
Create or modify the smb.conf configuration file at /etc/samba/smb.conf as follows:
[global]
server min protocol = SMB2
dos charset = CP932
unix charset = UTF-8
load printers = no
workgroup = WORKGROUP
server string = Samba Server
server role = standalone server
hosts allow = 192.168.10. 127.
log file = /var/log/samba/%m.log
max log size = 500
dns proxy = no
[homes]
comment = Home Directories
path = /data/share/personal/%U
browseable = no
writable = yes
[common]
path = /data/share/common
valid users = mako sato taka
writable = yes
create mode = 0770
directory mode = 0770
printable = noStarting and Enabling Samba Service #
Start the Samba service:
sudo systemctl start smb.serviceEnable the service to start at boot:
sudo systemctl enable smb.serviceConfiguring iptables #
To allow access to the file-sharing server from the LAN, permit incoming connections on TCP port 445.
For further details, refer to: iptables Configuration.
Example rule:
iptables -A INPUT -p tcp -s 192.168.10.0/24 --dport 445 -j ACCEPTVerifying Samba Functionality #
A Mac system can be used to verify connectivity using Finder’s Connect to Server feature. Navigate to Go > Connect to Server, enter the server’s IP address, and provide the configured username and password. If the shared directories appear, the setup is successful.