Samba is a utility that helps users to share files between different systems running over the same network. You can use Samba software to make a local network inside a home or office. You can also access remote servers and cloud services over the internet using Samba servers. Samba software can also provide security and authentication features for network users.
If you require sharing files between Windows and Linux machines that are on the same network, then you need to install Samba. You can also configure two different Linux machines over the same network and share files across them. In this brief tutorial, we will guide you through the process of sharing files using a Samba server and client connection on Arch Linux.
- How to Install Samba Server on Arch Linux?
- Configure Samba Server on Arch Linux
- Configure Samba Server for Client
Samba server can be easily installed through the official Pacman repository. You just need to utilize the Pacman command. Before we move towards the installation of Samba, make sure the following prerequisites are followed or installed:
- Arch Linux System (Server Side)
- Any other machine: Windows or any Linux distributions (Client side)
- Sudo Privileges
- A text editor, I will be using the Nano text editor
- A working network connection
Now let’s move toward the installation of Samba on the Arch Linux system.
First, update your Arch Linux system package registry:
sudo pacman -Syu
Next, use the Pacman command to install Samba:
sudo pacman -S samba
Once Samba is installed, verify its installation using this command:
The above command will give you the directory where Samba is installed. You can also verify the Samba installation by checking the Samba version:
The latest 4.19.4 version is installed on your Arch system.
To configure Samba, you need to create a /etc/samba/smb.conf file. The Samba package doesn’t contain this file, so you have to make it yourself before you start smb.service. You can use the smb.conf.default file from the Samba git repository as an example.
Check out the Samba official Arch Wiki for more information.
Open the documented example from the Samba git repository and copy the whole text.
Then, we can go back to the terminal and navigate to the /etc/samba directory and list the contents of this directory:
cd /etc/samba/ ls
We will see that it is empty, except for a subdirectory called private. Here, we need to make a file called smb.conf in this directory. To do this, we can type:
sudo nano smb.conf
This will open the nano text editor with an empty file. We can paste the text we copied from the web by pressing the Ctrl + V key. If you are using vim editor, you can paste the content using insert mode (pressing i) and then pressing Shift + Insert on the keyboard. This will insert the text into the document.
Now that we have the configuration file, we can easily edit some options to suit our needs. The first thing we want to do is to change the workgroup name. The workgroup name refers to the network group name that the Samba server belongs to. By default, it is set to MYGROUP, but we can change it to something more standard, such as WORKGROUP. This will make connecting to the Samba server from Windows or Linux computers easier.
To change the workgroup name, we can find the line that says:
workgroup = MYGROUP
And replace MYGROUP with WORKGROUP, like this:
workgroup = WORKGROUP
If you have Windows 10, you can change your workgroup settings by opening the Control Panel and going to the System and Security settings. Here, look for the workgroup parameter under the System section.
Next, we want to create a share. A share is a folder that we want to make accessible to other computers on the network. We can create a share by adding a new section at the file end. The section starts with a name enclosed in square brackets, followed by some options. For example, we can create a share called My Samba Share by adding the following lines:
[sambashare] comment = My Samba Share path = /samba writable = yes browsable = yes create mask = 0700 directory mask = 0700 read only = no guest ok = no
Here, we have defined the following options, each of these lines allows specific permissions to the client for accessing the directory:
- comment: A description of the share
- path: The location of the folder on the server (We will create this folder after saving the file)
- writeable: Whether the clients can modify the share
- browseable: Whether the clients can see the share
- create mask: The permissions for the files created in the share
- directory mask: The permissions for the directories created in the share
We can change these options as we see fit, depending on our needs. For this tutorial, we will use these values as an example.
Now save and exit the Samba configuration/setting file.
Next, we need to set up the username and account for Samba Share. Samba uses the username details to authenticate and authorize access to the shared resources on the server. Samba can map the Windows username to the Linux username by using a file called /etc/samba/smbusers. The client will also require credentials to access the Samba server. This way, Samba can ensure that only authorized users can access the files and printers on the network.
To create a new system group called sambausers with the -r option, run this command:
sudo groupadd -r sambausers
Now add the user to the sambausers group with the -aG option. Here, you have to replace your system username. You can also create any additional user here:
sudo usermod -aG sambausers type_user_name_here
To make it secure, create a Samba password for the user with the -a option:
sudo smbpasswd -a type_user_name_here
To share files with Samba, create a directory containing files for sharing. Use mkdir to create the directory /samba under /home:
sudo mkdir /samba
Next, change the group ownership of the /samba directory and all its contents to sambausers:
sudo chown -R :sambausers /samba
Now set the permissions of the /samba directory. Run the given chmod command to give the group and the owner write, read, and execute access. This will also limit the access for other users. It will also set the sticky bit. The restriction implies that only the owner or the group can remove or rename files inside the directory.
sudo chmod 1770 /samba
Finally, enable and start the smb service. It is the main Samba daemon that provides file and print services to clients using the SMB protocol:
sudo systemctl enable --now smb
Similarly, enable and start the nmb service. It is the NetBIOS name server that allows clients to access the Samba server by hostname:
sudo systemctl enable --now nmb
To make sure your Samba settings are correct, use the testparm tool. It will look at the /etc/samba/smb.conf file and notify you if there are any errors.
If you see the Loaded services file OK, everything is fine. Now you can use your Samba server with the Global Settings you chose.
Before proceeding to the client side, first check the IP address of the Samba server. This IP address will be needed to connect to the Samba directory from the client side.
Samba’s server side is set. Now we get to the Client service.
To connect with the Samba server, you have to mount it on the Samba client side using the mount option. You can mount the Samba server directory using the IP address.
Let’s configure the Samba client side.
First, open the file manager on your client machine. Select the Other Locations option.
Enter the server address and select Connect:
Replace the IP address with your server-side IP.
Provide the Username, Domain, and Password for authentication. Here, the username is the one we configured for sambausers, and the domain name is the workgroup defined inside the Samba configuration file. Next, hit the Connect button.
Now your client system is successfully connected with the Samba server, and you will see the Server share folder is mounted on your client PC.
Now create a test folder on your client system, and you will see the same folder will be created on your server side. To access the folder on the server side, open the /samba directory and use the ls command.
Now, delete the folder and unmount the shared Samba server directory.
As we have tested the Samba server, now it’s time to create a server directory on the Client computer and connect it with the Samba Server side. This way, you don’t have to set up the IP address every time you need to connect to the Samba server.
First, make a directory using this command on the client terminal:
Enter the directory to confirm its creation:
Now mount a remote Samba share named sambashare from the server with IP address 192.168.00.00 to a local directory named /home/linux/server on your Arch Linux machine. The -t cifs option specifies the file system type as Common Internet File System (CIFS). It is a dialect of SMB (Server Message Block) protocol.
To mount a Samba share, you can utilize the mount cifs command:
sudo mount -t cifs //192.168.18.58/sambashare /home/linux/server -o username=linux,password=asd,uid=1000,gid=1000,workgroup=workgroup
You have to enter the UID and GID of the server computer. To get both these values, run the id command on the Server computer:
Change the directory to the server and create a test file using the touch command:
cd server/ touch file1.txt ls
Now go to the server side and confirm the file is also created there.
cd /samba/ ls
The Samba server is successfully connected with the Samba client on two different Linux machines.
Samba is a utility that helps users to share files between different systems running over the same network. Samba software can be utilized to make a local network inside a home or office. To install Samba on your Arch Linux system, simply use the Pacman package manager. Samba is easy to get on Arch Linux, but the main task is the configuration of the client and server side. You have to configure the IP address and set a new user to access the Samba server from the client side. Similarly, you can also create multiple user Domains and passwords for connecting with the server.