Home / How To / How to install Samba Server on CentOS 8

How to install Samba Server on CentOS 8



Samba is a free and open source software that can be used to share files, folders and printers between Linux and Windows systems. It is also used for authentication and authorization, name resolution and service announcement. It can run on various operating systems including, Linux, Unix, OpenVMS and many more.

In this tutorial we will teach you how to install Samba and configure it as a standalone sharing server on CentOS 8.

Prerequisites [19659004] A server running CentOS 8.
  • A root password is configured on your server.
  • Installing Samba Server

    By default, the Samba package is available in the CentOS repository. You can install it with the following command:

      dnf install samba samba-common samba-client -y 

    After installing Samba, start the SMB service and enable it to boot after system startup with the following command:

      systemctl start smb 
    systemctl enable smb

    You can now verify the Samba service with the following command:

      systemctl status smb 

    You should get the following output:

    ? smb.service - Samba SMB Daemon
    Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor setting: disabled)
    Active: active (running) since Mon 2020-03-02 23:03:30 EST; 8s ago
    Document: man: smbd (8)
    man: samba (7)
    man: smb.conf (5)
    Main PID: 2072 (smbd)
    Status: "smbd: ready to serve connections ..."
    Details: 4 (limit: 25028)
    Memory: 33.8M
    CGroup: /system.slice/smb.service
    ?? 2072 / usr / sbin / smbd - foreground - no-process group
    ?? 2074 / usr / sbin / smbd - in the foreground - no-process group
    ?? 2075 / usr / sbin / smbd - in the foreground - no-process group
    ?? 2076 / usr / sbin / smbd - foreground - no-process group
    

    Create a public share with Samba

    In this section we will create a public share with Samba so that everyone can access the public share catalog without a password.

    Create a Public Share Directory

    First, create a shared folder named public and also create two files in the public directory:

      mkdir -p / samba / share / public 
    touch / samba / share / public / file1
    .txtebrit19459016 ?? touch / samba / share / public / file2.txt

    Then assign necessary permissions and ownership with the following command:

      chmod -R 0755 / samba / share / 
    chmod -R 0755 / samba / share / public
    chown -R none: none / none / samba / share
    chown -R none: none / samba / share / public

    Configure Samba

    Then you need to configure Samba for to share a public directory.

    First, create a backup of the /etc/samba/smb.conf file with the following command:

      etc. /etc/samba/smb.conf /etc/samba/smb.bakebrit19659009??Next, create a new Same configuration file: 

      nano /etc/samba/smb.confebrit19659009achteAdd the following lines: 

     [global]
    workgroup = WORK GROUP
    server string = Samba Server% v
    netbios name = samba server
    security = users
    map to guest = poor user
    dns proxy = no
    
    [Public]
    path = / samba / share / public
    surfable = yes
    writable = yes
    guest ok = yes
    read only = no
    

    Save and close the file. Then restart the Samba service to apply the changes:

      systemctl restart smb 

    Then test the Samba configuration with the following command:

      testparm 

    You should see the following output:

     Download smb config files from /etc/samba/smb.conf
    Loaded service file OK.
    Server role: ROLE_STANDALONE
    
    Press enter to see a dump of your service definitions
    
    # Global parameters
    [global]
    dns proxy = No.
    map to guest = poor user
    netbios name = SAMBA SERVER
    security = USER
    server string = Samba Server% v
    idmap config *: backend = tdb
    
    
    [Public]
    guest ok = Yes
    path = / samba / share / public
    read only = No.
    

    Configure SELinux and firewall

    Then set the correct SELinux boolean and security context values ​​to the sharing directory with the following command:

      setsebool -P samba_export_all_ro = 1 samba_export_all_rw = 1 
    samanage-samatage-samanage /public(/.*)?"isie19459023] restorecon / samba / share / public

    Then all Samba services through firewall with the following command:

      firewall-cmd --add -service = samba - zone = public --permanent 
    firewall cmd - load

    Access Samba Share from Ubuntu Gnome

    To access the Samba section, go to the remote machine, open the Gnome file manager and click Connect [19659040] to Server as shown below:

     Access SAMBA from Gnome

    Enter your Samba server IP address and click the Connect button. After successful connection you should see Samba share on the following screen:

     Samba share in File explorer

    Now click on the Public directory, you would see your files on the following screen:

     File list

    Access to Samba Share from Ubuntu Command Line

    You can also access the Samba section from the command line.

    First list all available Samba parts with the following command:

      smbclient -L //45.58.38.51vud19659009??You should see the following output: 

     Domain = [WORKGROUP] OS = [Windows 6.1] Server = [Samba 4.10.4]
    
    Sharename Type Comment
    --------- ---- -------
    Public disk
    IPC $ IPC IPC Service (Samba Server 4.10.4)
    Domain = [WORKGROUP] OS = [Windows 6.1] Server = [Samba 4.10.4]
    
    server Comment
    --------- -------
    
    Workgroup Master
    --------- -------
    

    You can also mount the Samba share with the cifs protocol. To do so, install the cifs-utils package with the following command:

      apt-get install cifs-utils -y 

    Then mount the samba part in the directory / mnt with the following command:

      mount - t cifs //45.58.38.51/public / mnt / 

    You will be prompted for the password shown below:

     Password for [email protected] // 45.58.38.51/public:
    

    Just press Enter without entering any password to mount the Samba share:

    You can now access the Samba share in / mnt direcotry:

      ls / mnt / [19659008] You should see the following output: 

     file1.txt file2.txt
    

    Creating Private Sharing with Samba

    In this section, we will create a private sharing with Samba so that only authenticated users can access the private sharing directory.

    Create user and group

    First create a group named private with the following command:

      groupadd private 

    Then create a new user named privateuser and add it to the private group:

      useradd -g private privateuser 

    Next, set the password for the user with the following command:

      smbpasswd -a privateuser 

    Output:

     New SMB password:
    Enter new SMB password:
    Added users private users.
    

    Create a private sharing directory

    Then create a shared folder named private and also create two files in private directory:

      mkdir -p / samba / share / private 
    touch / samba / share / private / private1.txt Chapter19459016 ?? touch /samba/share/private/private2.txt tu 1919900900 Next, assign the correct state and ownership with the following command:

      chmod -R 0770 / samba / share / private 
    chown -R root: private / samba / share / private

    Then configure SELinux context for private directory with the following command:

      semanage fcontext –at samba_share_t "/ samba / share / private (/.*)?" 
    restorecon / samba / share / private

    Configure Samba

    Then open the Samba configuration file and define the private sharing:

      nano /etc/samba/smb.conf Chapter19659009vardAdd the following lines to the end of the file: 

     [Private]
    path = / samba / share / private
    valid users = @ private
    guest ok = no
    writable = yes
    surfable = yes
    

    Save and close the file and then restart the Samba service to apply the changes:

      systemctl restart smb 

    Next, check the Samba configuration with the following command:

      testparm 

    You should see the following output :

     Load smb configuration files from /etc/samba/smb.conf
    Loaded service file OK.
    Server role: ROLE_STANDALONE
    
    Press enter to see a dump of your service definitions
    
    # Global parameters
    [global]
    dns proxy = No.
    map to guest = poor user
    netbios name = SAMBA SERVER
    security = USER
    server string = Samba Server% v
    idmap config *: backend = tdb
    
    
    [Public]
    guest ok = Yes
    path = / samba / share / public
    read only = No.
    
    
    [Private]
    path = / samba / share / private
    read only = No.
    valid users = @ private
    

    Access Samba Share from Ubuntu Command-line

    First, access the available share with the following command:

      smbclient-L //45.58.38.51 To 1919900900 You should see the following output: 

     Domain = [WORKGROUP] OS = [Windows 6.1] Server = [Samba 4.10.4]
    
    Sharename Type Comment
    --------- ---- -------
    Public disk
    Private disk
    IPC $ IPC IPC Service (Samba Server 4.10.4)
    Domain = [WORKGROUP] OS = [Windows 6.1] Server = [Samba 4.10.4]
    
    server Comment
    --------- -------
    
    Workgroup Master
    --------- -------
    

    Then, connect to the Samba server and list the available sharing with the following command:

      smbclient //45.58.38.51/private -U privateuser 

    You will be prompted for a password that appears below: [19659014] Enter private user password:

    Type your password and press Enter to access the Samba shell as below:

     Domain = [WORKGROUP] OS = [Windows 6.1] Server = [Samba 4.10.4]
    smb: >
    

    Now list the available split with the following command:

      smb: > ls 

    You should see the following output:

    . D 0 Tue Mar 3 10:03:22 2020
    .. D 0 Tue Mar 3 10:01:56 2020
    privat1.txt N 0 Tue Mar 3 10:03:17 2020
    privat2.txt N 0 Tue Mar 3 10:03:22 2020
    
    51194 blocks in size 2097152. 49358 blocks available
    

    Now exit from the Samba shell with the following command:

      smb: > exit 

    You can also mount the Samba share on the / opt directory:

      mount -t cifs -o user = privateuser / /45.58.38.51/private / opt 

    You will be asked to enter a password as shown below:

     Password for [email protected] // 45.58.38.51/private: *********
    

    Enter your password and press Enter to assemble the Samba share.

    You can now check your Samba split in the / opt directory as shown below:

      ls / opt / 

    Output:

     private1. txt privat2.txt
    

    Access Samba Share from Ubuntu Gnome

    To access the Samba share, go to the remote machine, open the Gnome file manager and click Connect to Server that appears below:

     Gnome access to private part

    Enter your Samba server IP address and click the Connect button. After a successful connection you should see the Samba share on the following screen:

     Public and private sharing

    Now click on the catalog Private enter your username and password and then click Connect button. You should see your files on the following screen:

     Log in with username and password

     Files

    Congratulations! you have installed and configured the Samba server on CentOS 8.


    Source link