Chat Zalo Chat Messenger Phone Number Đăng nhập
How to share files with Samba | Enable Sysadmin - Red Hat

How to share files with Samba | Enable Sysadmin – Red Hat

The Samba project provides printing and file sharing services for computers on a network. It uses the Server Message Block protocol and Common Internet File System (SMB/CIFS), so services created when running Samba are available to Linux, macOS, and Windows clients. It’s an essential service to run in organizations that support multiple operating systems, and it’s even useful in homogeneous networks.

It’s not hard to set up, and all you need is at least one server that you want to designate as a file sharing host (it doesn’t have to be rack-mounted, and it could even be a dedicated workstation). For client access, Samba is either integrated into the operating system or easily installed from a repository.

Install

Samba

On your designated Samba server, install the Samba package:

$ sudo dnf install samba

This command also installs the samba-common-tools and samba-libs packages

.

Then, start the SMB and NMB daemons. The SMB daemon manages most Samba services, while the NMB daemon provides NetBIOS services. Here are the commands:

$ systemctl enable -now smb $ systemctl enable -now nmb

That’s the installation. All that’s left is a bit of setup.

Configure the firewall Make sure your file share server is accessible across your network by adding the Samba service to your firewall

config

: $ sudo systemctl enable -now firewalld $ sudo firewall-cmd -list-services cockpit dhcpv6-client ssh $ sudo

firewall-cmd -add-service

samba success

Configure Samba

Create a directory on the server to contain your shared files and folders, and change the SELinux context to samba_share_t:

$ sudo mkdir /sambashare $ sudo chcon -t samba_share_t /sambashare/

To configure shares and users, edit the /etc/samba/smb.conf file. The default file has several good examples of common options, including layouts for shared printers and home directories.

There is a global section, which defines a working group. I arbitrarily set mine to SAMBA. I don’t have any other existing workgroups on my network, so the workgroup hardly matters for my setup. If your organization has a specific workgroup structure, follow that.

[global] workgroup = SAMBA security = user passdb backend = tdbsam …

By default, the NetBIOS name of the Samba server is the Linux hostname of the server. If you don’t have DNS configured on your local network, you can use the server’s IP address when communicating with the Samba server.

[ Download the Linux networking cheat sheet for a list of Linux utilities and commands for managing servers and networks. ]

Create

a shared location

To create a new shared location, add a section to the /etc/samba/smb.conf configuration file with these two definitions:

[sambashare] path = /sambashare read only = No

Each section of this configuration file defines a service. When users access a Samba server, they connect to a service with the name of one of the bracket sections in the configuration, such as [sambashare], [homes], [print$], and so on. Most users don’t need to be aware of this subtlety, but you might see these service names when testing and troubleshooting.

You can test your

Samba configuration with the command testparm: $ testparm /etc/samba/smb.conf

Add

users

Users who log on to a Samba share must have accounts on the server or log on as guests. You can also use standard Unix groups to manage access. For example, run the following command to create a group of staff members who need access

to the server: [server]$ sudo groupadd staff

Assuming you need to add a staff member named tux to your Samba server, the process is initially the same as usual

: [server]$ sudo adduser -g staff -create-home tux [server] $ passwd tux

You should also set a dedicated Samba password:

[server] $ sudo smbpasswd -a tux

[ Keep essential commands handy. Download the Linux command cheat sheet.

]

Restart and test

Samba

To load into the new configuration, restart Samba:

[server]$ sudo systemctl restart {s,n}mb

Samba is now serving sambashare to any authenticated user. You can test it using

the smbclient command: [client]$ smbclient -L //sambaserver Enter the SAMBAtux password: Shared name type Comment – – – sambashare Disk printing$ IPC$ IPC Disk Printer Drivers IPC Service (Samba 4.14.5) tux Disk home directory

Users can access their Samba shares through file managers, terminal commands and other services that communicate over SMB. For example, in KDE Dolphin:

(Seth Kenlon, CC BY-SA 4.0)

File sharing with Samba Setting up

file sharing with

Samba is easy and provides flexible cross-platform collaboration. Additional configuration options are available when using workgroups and domains or when Samba is the Active Directory domain controller. It’s built into all major operating systems, has rich terminal and GUI tools, and is quick to set up. Help your users break down silos and share data with Samba.

Contact US