Samba - Sharing Files in a Network
Samba is a free and open-source re-implementation of the SMB/CIFS network file sharing protocol that allows end users to access files, printers, and other shared resources.
Last update: 2022-06-22
Table of Content
Installation#
Samba is available from the official Ubuntu repositories. To install it on Ubuntu system follow the steps below:
-
Start by updating the apt packages index:
sudo apt update
-
Install the Samba package with the following command:
sudo apt install -y samba
-
Once the installation is completed, the Samba service will start automatically. To check whether the Samba server is running, type:
sudo systemctl status smbd
smbd.service - Samba SMB Daemon Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-07-12 15:30:57 +07; 1min 41s ago Docs: man:smbd(8) man:samba(7) man:smb.conf(5) Main PID: 4059 (smbd) Status: "smbd: ready to serve connections..." Tasks: 4 (limit: 2329) CGroup: /system.slice/smbd.service ├─4059 /usr/sbin/smbd --foreground --no-process-group ├─4061 /usr/sbin/smbd --foreground --no-process-group ├─4062 /usr/sbin/smbd --foreground --no-process-group └─4064 /usr/sbin/smbd --foreground --no-process-group Jul 12 15:30:57 ubuntu18 systemd[1]: Starting Samba SMB Daemon... Jul 12 15:30:57 ubuntu18 systemd[1]: Started Samba SMB Daemon.
Add a user#
Samba has its own user management system. However, any user existing on the samba user list must also exist within/etc/passwd
file. Use the smbpasswd
command to add a user to Samba user list:
sudo smbpasswd -a $USER
Configuration#
Before making changes to the Samba configuration file, create a backup for future reference purposes:
sudo cp /etc/samba/smb.conf{,.backup}
Edit the Samba configuration file
sudo nano /etc/samba/smb.conf
The default configuration file that ships with the Samba package is configured for standalone Samba server. Open the file and make sure server role
is set to standalone server
.
...
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
server role = standalone server
...
Uncomment the [home]
section, then edit its options as below:
[homes]
comment = Home Directories
browseable = yes
read only = no
create mask = 0700
directory mask = 0700
valid users = %S
Use mask 0775
to enable execution permission.
Save the file, then test the parameters by running the utility testparm
to see the configs:
testparm
testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
dns proxy = No
log file = /var/log/samba/log.%m
map to guest = Bad User
max log size = 1000
obey pam restrictions = Yes
pam password change = Yes
panic action = /usr/share/samba/panic-action %d
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
passwd program = /usr/bin/passwd %u
server role = standalone server
server string = %h server (Samba, Ubuntu)
syslog = 0
unix password sync = Yes
usershare allow guests = Yes
idmap config * : backend = tdb
[homes]
browseable = No
comment = Home Directories
create mask = 0700
directory mask = 0700
read only = No
valid users = %S
[work]
path = /mnt/work
comment = Workspace
create mask = 0700
directory mask = 0700
read only = No
Then restart the service:
sudo service smbd restart
Finally, connect to the Samba Server from another computer with username and password set in above steps. The path to the Samba server can be located by IP Address, e.g. \\192.168.100.12\<username>
or by a computer name, e.g. \\ubuntu\<username>
.
Quick clear the config file after making a backup:
sudo bash -c 'echo "" > /etc/samba/smb.conf'