Expected Reading Time: 7 minutes

Welcome to this practical blog article where I will show you step by step how to set up Samba (SMB) on an Ubuntu Linux system. This guide will help you to quickly and efficiently create a working Samba environment to share files between different operating systems.

What is Samba?

Samba is an open source software that implements the SMB/CIFS network protocol. It allows you to share files and printers over networks consisting mainly of Windows computers, although it is also compatible with other operating systems such as macOS and Linux.

Preparations

Before you start, make sure that your Ubuntu system is up to date. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade

This ensures that all existing packages are updated to the latest available versions.

Install Samba

Now install Samba with the following command:

sudo apt install samba

After installation, check whether the Samba service is running:

sudo systemctl status smbd

You should see an output confirming that the service is active and running.

Configuration of Samba

Now edit the Samba configuration file to set up your shares:

  • Open the configuration file with a text editor of your choice, here I use nano:
sudo nano /etc/samba/smb.conf
  • At the end of the file, add the configuration for the share. Here is a simple example of a share called "YouTube-EN":
    • the text editor nano you can close with Ctrl + C and then confirm the save by pressing Y on the keyboard
[YouTube-EN]
   path = /mnt/cache/appdata
   public = yes
   writeable = yes
   comment = complete harddrive data
   force group = root
   force user = root
   create mask = 0770
   directory mask = 0771
   force create mode = 0660
   force directory mode = 0770
   acl allow execute always = yes

Explanation of the configuration

  1. path = /mnt/cache/appdata
    • This determines the local path on the server that is shared. All files and subfolders in /mnt/cache/appdata are accessible via the network.
  2. public = yes
    • This setting makes the share public, i.e. anyone in the network can access it without having to authenticate themselves.
  3. writeable = yes
    • This allows users to create, modify and delete files within the share. This setting is identical to writable = yes.
  4. comment = complete harddrive data
    • This is a descriptive comment on the release. This text is used to provide users with information about the content or purpose of the release.
  5. force group = root
    • All operations on the share are treated as if they were performed by the user group root regardless of the actual group membership of the user accessing the share.
  6. force user = root
    • Similar to force group this setting ensures that all operations are treated as if they were performed by the user. root would be executed. This can harbor security risks, as root has full system rights.
  7. create mask = 0770
    • This defines the permissions for newly created files in the share. The permissions 0770 mean that the owner and the group have full rights (read, write, execute), while others have no rights.
  8. directory mask = 0771
    • Sets the permissions for newly created directories. The owner and group can do everything here, while others can only enter the directory.
  9. force create mode = 0660
    • This enforces the minimum permissions that are assigned to newly created files, regardless of other settings or system permissions. Only the owner and the group have read and write permissions here.
  10. force directory mode = 0770
    • Similar to force create modebut for directories. This ensures that new directories are always created with the 0770 permissions.
  11. acl allow execute always = yes
    • This setting allows the execution of executable files in the share, even if the other authorizations would not allow this.

This configuration offers fairly open accessibility, but combines the use of root as a forced user and group, which can be a security concern, especially in environments with many users or if the network is publicly accessible. It is important to closely monitor and evaluate the security of this type of sharing to minimize potential risks.

However, since we are in the home network and you are probably the only user and the server is not accessible via the Internet, we don't care. Nevertheless, the warning that you should not use such a configuration publicly or in a company. not should use!

In order to better understand the numbers for the authorizations, it is best to use the page https://chmod-calculator.com/ where you can click on the numbers or desired rights to see exactly what the numbers mean. Thus with 0770 for example rwxrwx---This applies to read, write and execute rights for the owner and group, but no rights for others. chmod changes the access rights of files and folders.

Restart Samba

To load the new configurations, restart Samba:

sudo systemctl restart smbd

Test access to the share

You can now try to access the share from another computer on the network. Under Windows, for example, you can do this by entering \\\YouTube-EN in the address bar of the file explorer. Example: \\192.168.178.79\YouTube-DE

Permanently integrate network address in Windows

If you want to add a network address in Windows without assigning a network drive with a specific drive letter, you can add the network directory as a network location. This process is especially useful if you need quick access to a network folder without having to assign a drive letter to it. Here are the steps to add a network location in Windows Explorer:

Step 1: Open Windows Explorer

  • Press Windows key + E or click on the Explorer icon in your taskbar to open Windows Explorer.

Step 2: Add network location

  • Navigate to "This PC" in the left navigation area.
  • Right-click on an empty space in the window and click on "Add network address". This starts the wizard for adding a network location.

Step 3: Use wizards

  • In the wizard, click on "Next" to start the process.
  • Select "Select a custom network location" and click "Next" again.

Step 4: Specify network path

  • Enter the network address of the location you want to add. This could be a path to an SMB share, such as \\server name\share name or \\IP address\share name. Click on "Next" after the entry. Example: \\192.168.178.79\YouTube-DE
  • When prompted for credentials (if access needs to be authenticated), select "Use a different username". Enter your username and password, or leave it open for general use, depending on your requirements.

Step 5: Name the network location

  • Give the network location a name. This name is displayed in "This PC" under "Network addresses" and helps you to easily identify the location.

Step 6: Complete the process

  • Click on "Next" and then on "Finish" to complete the setup process. The new network location is now displayed in the list of network addresses under "This PC".

This setup gives you quick and easy access to your network resources directly from Windows Explorer, making file management and access to remote data much easier.

YouTube video implementation

https://youtu.be/GHoC6RowyRY

Conclusion

Congratulations, you have managed to set up Samba (SMB) on your Ubuntu Linux system! With this practical guide, you have learned how to configure a Samba share step by step to efficiently share files and printers between different operating systems. From installing Samba to configuring and testing the share, you have completed all the necessary steps.

The configuration you have set up, in particular with settings such as force user = rootshows that you have full control over access rights. This makes it possible to work efficiently in a controlled home network, despite the potential security risks. However, the use of such settings should be done with caution, especially in larger or publicly accessible networks.

In addition, you have learned how to integrate network addresses in Windows without assigning a drive letter, which is extremely useful for the flexibility of your network administration. This method makes it easier to access and manage network resources directly from Windows Explorer.

Your ability to overcome these technical challenges and make adjustments where needed makes you a competent administrator of your own network. Use your new Samba environment to increase your productivity and simplify the exchange of resources between different devices. Good luck with further optimizing and securing your network shares!

Categories: Self-hosted server

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

en_US