To create a file server on Ubuntu or Debian you can use the Samba protocol, which allows you to share directories between different operating systems over a network. This way, you will be able to access the files on your Ubuntu server from your Windows or macOS system.
Installation
To install Samba on Ubuntu, run the following command:
# apt update && apt install samba -y
To verify the installation, you can use the following command:
# whereis samba
You should see the following output or something similar:
samba: /usr/sbin/samba /usr/lib/samba /etc/samba /usr/share/samba /usr/share/man/man7/samba.7.gz /usr/share/man/man8/samba.8.gz
Configure shared directory
If you don’t have a directory, you need to create one. Run the following command, modifying it with your username to create it in your home directory:
# mkdir /SAMBA
Then, include the directory in the Samba configuration file using an editor like nano:
# nano /etc/samba/smb.conf
Add the directory to the configuration file as follows:
[SAMBA]
comment = Shared folder via Samba on Ubuntu
path = /SAMBA
hosts allow = 0.0.0.0
hosts deny = 10.20.10.1
guest ok = no
read only = no
browsable = yes
With this configuration, writing will be allowed. You can modify the "read only" value to "yes" if you need read-only access and also change "browsable" to "no" to prevent navigation through other directories in the path.
In hosts allow, you can specify which devices or networks are allowed access, and in hosts deny, you can specify which ones should be blocked.
To save the changes, press Ctrl-O and to exit the nano text editor, press Ctrl-X.
Then, restart the service to apply the modified configuration changes:
# systemctl restart smbd.service
Warning
Remember that for security reasons, you must allow or check the corresponding port in the Clouding panel firewall for the network you are using, and also in your system's firewall if it is enabled. If you are not using a VPN connection, create the rule only for the specific addresses that need access. The default port used by Samba for file sharing is 445/TCP.
Finally, the Samba service does not use system credentials. You will need to enter or assign one for the Samba user:
# smbpasswd -a user
Additionally, to list Samba users, you can run the following command:
# pdbedit -L -v
Access the shared resource
To access your shared folder, simply enter the protocol used, the server address, and the shared directory from your file explorer:
smb://SERVER_IP/SAMBA
You will then be prompted to enter the credentials of the previously created Samba user. On a Windows system, you can access it directly without specifying the protocol:
\\SERVER_IP\SAMBA
If you want name resolution, you will need to open the appropriate ports in case you are using an Active Directory. You can also edit your hosts file or specify the Samba file server in your name server to avoid accessing it via IP address.
We hope this tutorial has helped you 🙂. Remember, if you have any questions about this or any other issue related to your Clouding servers, don’t hesitate to contact soporte@clouding.io We’re here to help!