samba server in linux

How to Share Folder Between Two Linux Servers

Often you may need to share folders between two Linux servers. Samba is a network utility commonly used to share files & data between two Linux systems. It is a cross-platform server that allows you to share files & data not only across Linux systems but also between Windows & Linux systems. In this article, we will learn how to setup Samba server and share folder between two Linux servers.

How to Share Folder Between Two Linux Servers

Here are the steps to share folder between two Linux servers.

1. Install Samba

Open terminal and run the following commands to install Samba.

$ sudo apt-get update
$ sudo apt-get install samba

2. Set Password for Samba

Run the following command to set password for Samba.

$ sudo smbpasswd -a <user_name>

Please note, Samba uses a separate set of passwords than the standard Linux system accounts (stored in /etc/samba/smbpasswd), so you’ll need to create a Samba password for yourself.

We have assumed that you will use your own user and have not covered situations involving other users passwords, groups, etc.

3. Create Folder for Sharing

Run the following command to create a folder to be shared. Replace <user_name> and <folder_name> with your username and folder name respectively.

$ sudo mkdir /home/<user_name>/<folder_name>

4. Backup Your Samba Configuration

Run the following command to take a backup of Samba configuration file.

$ sudo cp /etc/samba/smb.conf ~

5. Edit Samba Configuration

Open Samba configuration file in a text editor.

$ sudo vi /etc/samba/smb.conf

Add the following lines to the very end of file.

path = /home/<user_name>/<folder_name>
valid users = <user_name>
read only = no

Here we have specified the path of folder that will be shared, the user that has valid access, and that it is not read-only access.

6. Restart Samba Service

Run the following command to restart Samba service.

$ sudo service smbd restart

Once the server has restarted run the following command to check if there are any errors in configuration file.

$ testparm

7. Access Network Share

You can install the samba client with the following command to view network share.

$ sudo apt-get install smbclient

and run the following command to list all shares

# List all shares:
smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>
# connect:
smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>

In this article, we have learnt how to share folders in Linux using Samba service. You can customize these steps as per your requirement.

Also read:

How to Disable SELinux in CentOS & RHEL
How to Setup SSH Tunneling in Linux
How to Save Terminal History in Linux
How to Delete All Instances of Character from Python String
How to Randomly Select Item from Python List

Leave a Reply

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