Today, sharing folders between different computers is nothing new, either at home or in the workplace. In this trend, the modern operating system through the network file system to make the exchange of data between computers simple and transparent. If you work in an environment that includes both Microsoft Windows and Linux, a shared file and directory is shared via a cross-platform network file sharing protocol: Smb/cifs. Windows native support Smb/cifs,linux also implemented the SMB/CIFS protocol through open source software Samba.
In this article, we'll show you how to share a folder with Samba . The Linux platform we use is fedora or CentOS. This article is divided into four parts. First, we install Samba in a fedora/centos environment. Next, we discuss how to adjust the SELinux and firewall configuration to allow Samba file sharing. Finally, we show you how to use Samba to share folders.
Step 1: Install Samba on fedora and CentOS
First, install Samba and make some basic configuration.
Verify that Samba is installed on your system:
$ rpm-q Samba Samba-common samba-client
If the above command does not have any output, this means that samba is not installed. At this point, you should use the following command to install Samba.
$ sudo yum install samba Samba-common samba-client
Next, create a local folder to share on the network. This folder should be exported to a remote user in a way that Samba shares. In this guide, we will create this folder in the top-level folder '/', so make sure you have the appropriate permissions.
$ sudo mkdir /
If you want to create a shared folder within your home folder (for example, ~/shared), you must activate the Samba Home folder sharing option in SELinux, as described later.
After you create the/shared folder, set the folder permissions to ensure that the remaining users can access it.
$ sudo chmod o + /shared
If you do not want other users to have write access to the folder, you need to remove the ' w ' option from the command.
$ sudo chmod o + /
Next, create an empty file to test. This file can be used to verify that the share of samba has been mounted.
/ shared /
Step 2: Configure SELinux for Samba
Next, we need to configure SELinux again. SELinux is enabled by default in the Fedora and CentOS distributions. SELinux allows Samba to read and modify files or folders only under the correct security configuration. (For example, add the ' Sambasharet ' attribute tag).
The following command adds the necessary tags for the configuration of the file:
--samba_share_t"<directory> (/.*)?"
will be replaced with the local folder we created previously for the samba share (for example,/shared):
--samba_share_t"/shared (/.*)?"
We must execute the RESTORECON command to activate the modified label, as follows:
--/
In order to share the folder in our home folder through Samba, we must turn on the option to share home folder in SELinux, which is turned off by default. The following command can achieve this effect. If you do not share your home folder, you can skip this step.
-1
Step 3: Configure the firewall for Samba
The following command is used to open the TCP/UDP port required for Samba sharing in the firewall.
If you are using FIREWALLD (for example, under Fedora and CentOS7), the next command will permanently modify the samba-related firewall rules.
$ sudo firewall - ----add-service =
If you use Iptables (for example, CentOS6 or earlier) in your firewall, you can use the following command to open the necessary outward ports for samba.
$ sudo vi/etc/Sysconfig/iptables-A RH-Firewall-1-INPUT-m State--State NEW-m TCP-p TCP--Dport445 -J ACCEPT-A RH-Firewall-1-INPUT-m State--State NEW-m UDP-p UDP--Dport445 -J ACCEPT-A RH-Firewall-1-INPUT-m State--State NEW-m UDP-p UDP--Dport137 -J ACCEPT-A RH-Firewall-1-INPUT-m State--State NEW-m UDP-p UDP--Dport138 -J ACCEPT-A RH-Firewall-1-INPUT-m State--State NEW-m TCP-p TCP--Dport139 -J ACCEPT
Then restart the Iptables service:
Step 4: Change the Samba configuration
The following steps are used to configure Samba to export the local folder as a Samba shared folder.
Use the file editor to open the Samba configuration file and add the following line to the end of the file.
/ etc / Samba / SMB . [myshare]comment=my shared files path=/sharedpublic=Yeswriteable =Yes
The above bracketed text (for example, "MyShare") is the name of the resource that Samba shares, and it is used to access Samba shares from a remote host.
Create a Samba user account, which is required to mount and export the Samba file system. We can use the SMBPASSWD tool to create a samba user. Note that the Samba user account must be an existing Linux user. If you try to use SMBPASSWD to add a non-existent user, it returns an error message.
If you do not want to use any existing Linux user as a samba user, you can create a new user in your system. For security purposes, set the logon script for the new user to/sbin/nologin, and do not create the user's home folder.
In this example, we created a user named "Sambaguest", as follows:
--/sbin/nologin sambaguest
After creating a new user, use the SMBPASSWD command to add the samba user. When this command asks for a password, you can type a password that is different from the user's password.
- a sambaguest
Activates the Samba service and detects if the samba service is running.
$ sudo systemctl enable SMB . $ sudo systemctl start SMB. is-active SMB
Use the following command to view a list of shared folders in Samba.
--
The next step is to access the Samba shared folders in the Thunar file Manager and copy copies of the File1. Note that the shared content of samba can be accessed by Smb://<samba-server-ip-address>/myshare this address in Thunar.
Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/
How to share with samba on fedora or CentOS