Your files from Windows, installing a Samba Server on Debian

3 minute read

Despite having different ways of accessing files on your server, perhaps all of them become somewhat tedious if we are used to browsing through Windows folders. I have recently discovered a very simple way to have a Samba file server in Debian and derivatives to be able to access the files on the server from a Windows client as if it were another folder.

Why do we need a Samba server to access files from Windows on a Linux server? Okay. By default, both systems use different file sharing protocols. Samba is a free implementation of the Microsoft Windows File Sharing Protocol (formerly called SMB, recently renamed CIFS) for UNIX-like systems.

Installation

Most of the following commands require root privileges to run. You can use sudo or log in as root user and save yourself typing the prefix in each command.

Install the Samba server package:

$ sudo apt update
$ sudo apt install samba -y

Enable the Samba service to start with the system:

$ sudo systemctl enable smbd

If you use the system firewall, you need to open the following ports:

$ sudo ufw allow 139
$ sudo ufw allow 445

Restart the smbd service and check that it’s running:

$ sudo systemctl restart smbd
$ sudo systemctl status smbd

  ? smbd.service - Samba SMB Daemon
  ...
  Status: "smbd: ready to serve connections..."
  ...

Setting up Samba Share

Edit the smb.conf file with the command sudo nano /etc/samba/smb.conf, adding the following to the end of the document:

[media]
comment = media folder
path = /media
writeable = yes
browsable = yes
public = no
valid users = danimart1991, root

I attach an explanation of each line:

  • [media]: It is the short name that describes what we are going to share. An identifier.
  • comment: A comment to describe what we are sharing.
  • path: The path of the folder we want to share.
  • writeable: Indicates if we want the folder to be read-only or if you want to allow writes and deletions to be carried out on it.
  • browsable: If this share is seen in the list of available shares in a network view and in the navigation list.
  • public: Indicates if the folder does NOT need a password to access it.
  • valid users: List of users who will have access to the folder.

You can see more options in the documentation of the configuration file.

We save the file with the F3 key and exit with F2.

Setting up Users

As you can see, I have indicated in the valid users field which users can access the files. These users must have access to the shared folder and its files, otherwise they will not be able to see them when access it from Windows.

In addition, these users have to be created on our server. If not, just use the command:

$ sudo useradd danimart1991

Next. You have to declare that user in Samba and assign a unique password for this service. For this, use the following command:

$ sudo smbpasswd -a danimart1991
New SMB password: xxxxxxxx
Retype new SMB password: xxxxxxxx

Finally, restart the service:

$ sudo systemctl restart smbd

Conclusion

We have already configured our Samba server for access from Windows. It is enough to open a File Explorer, write the server address and access indicating the credentials that have been previously created.

Server Access from Windows with Samba

Now you will have quick and easy access from your Windows devices to the server folders.

References

Leave a comment