Samba allows you to share your files over a local network to computers running any operating system. Samba also makes it simple to control access to these shares using a single configuration file. On Debian, that configuration is mostly set up for you, making configuring a Samba server on Debian a smooth experience.
In this tutorial you will learn:
- How to Install Samba
- How to Change Samba’s Global Settings
- How to Configure a New Share
- How to Set Up A Samba User
- How to Connect to a Share
Software Requirements and Conventions Used
|Requirements, Conventions or Software Version Used
|Debian 10 Buster
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
On Debian, you can install the Samba server right from the default Debian repositories. It’s a single package, so go ahead and install it.
$ sudo apt install samba
Change Samba’s Global Settings
Samba’s configuration can all be found in
/etc/samba/smb.conf. That file contains both the global configuration for Samba itself and your shares. Debian is usually good about providing intelligent default configurations that work immediately, but it can’t hurt to take a look at the provided settings, and make changes where necessary.
The first setting that you’ll find near the top of your general settings is the
workgroup. This determines the name of the Windows workgroup that your server will be a part of. The default value is
WORKGROUP because that’s also the default value on Windows. If you’re configured something different, change it here too.
workgroup = WORKGROUP
Next, you may want to limit access to your server. If you want to limit which computers can connect to your share, uncomment the
interfaces option, and specify an IP or range of IPs and an interface they can connect on.
interfaces = 192.168.1.0/24 eth0
If you’re not a fan of that method, you can always add the
hosts allow option to limit who can connect too. Just specify IP addresses or ranges after.
hosts allow = 127.0.0.1/8 192.168.1.0/24
The rest of the general settings are set to fairly solid defaults. You won’t need to change them to get your shares running, but feel free to have a look around and tweak anything you like.
Configure a New Share
There are already a few shares set up for you. They allow you to share the home folders of any user on the system and your printers. Actually, there’s already a print directory being shared. Change the
browseable value to
Now, try creating your own share. There are a ton of options that you can pick from for your Samba share, but this guide will cover the most common ones.
First, name your share, and place that name in brackets.
On the next line, tab in four spaces, and write a brief comment describing the share.
comment = My new share
Next, set the
path equal to the absolute path to the share.
path = /home/user/share
Choose whether you want to be able to browse to the share or need to manually mount it directly.
browseable = yes
Do you want people to be able to write to the share or mount it read only?
read only = no
Can guests access it? In Samba terms, guests are anonymous users that haven’t signed in to the share. In short, do you want to password protect the share or limit access to certain users?
guest ok = no
If guests can’t access the share, who can?
valid users = username
And, that’s it. There are other options and other ways to go about these basic steps, but they take you to more or less the same place. Unless you have something really specific in mind, these options should be enough. Put it together, and you get something like this:
comment = A new share
path = /home/nick/share
browseable = yes
read only = no
guest ok = no
valid users = nick
Save, and exit. Then, restart Samba.
# systemctl restart smbd
Set Up A Samba User
In order to connect to your share, unless you’re only using guest access, you’re going to need to set up Samba user accounts. It’s super quick, and only takes a single command.
# smbpasswd -a username
After that, you’ll be asked to enter a password for that user. That’s the password that their shares will be locked behind.
How to Connect to a Share
There are a couple of packages that you’ll need to connect to a Samba share. Go ahead, and install them.
$ sudo apt install samba-client cifs-utils
Now, you can open your file browser and navigate to the Network section. You’ll see your server listed there, and below that, the share that you just set up.
You’re ready to start creating your own Samba shares on Debian, and accessing them from your other Linux machines. There isn’t much else to it, and Samba will automatically start with Debian at boot..