How to install Samba on CentOS ?

Is this article teach you do basic samba? Oh~ no. This article introduces the server of samba. This server can help you to share files between Linux and Windows. The difference with FTP server is you can revise file directly on your PC. So let me show you how to install Samba server on Cent OS.

  • Install samba
  • [nick1811@centos-6 ~]$ sudo yum install -y samba
    
  • To allow folder access
  • [nick1811@centos-6 ~]$ sudo vim /etc/selinux/config
    
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    
  • To add samba user (Hint: Only Linux users can be added to samba user)
  • [nick1811@CentOS-6 ~]$ sudo pdbedit -a -u nick1811
    new password:
    retype new password:
    
  • Add user with password
  • [nick1811@CentOS-6 ~]$ sudo printf "********\n********\n" | sudo pdbedit -t -a -u nick1811
    Unix username:        nick1811
    
  • To delete samba user
  • [nick1811@centos-6 ~]$ sudo pdbedit -x -u nick1811
    
  • To check samba users
  • [nick1811@CentOS-6 ~]$ sudo pdbedit -L
    nick1811:500:nick1811
    
  • To enable samba on starting OS
  • [nick1811@centos-6 ~]$ sudo chkconfig smb on
    
  • Settings for creating shares by non-root users
    • create samba shares folder
    • [nick1811@CentOS-6 ~]$ sudo mkdir -p /usr/local/samba/lib/usershares
      [nick1811@CentOS-6 ~]$ sudo chown root:nick1811 /usr/local/samba/lib/usershares
      [nick1811@CentOS-6 ~]$ sudo chmod 1770 /usr/local/samba/lib/usershares
      [nick1811@CentOS-6 ~]$ sudo chcon -R -t samba_share_t /usr/local/samba/lib/usershares
      
    • set up your smb.conf by adding to the [global] section
    • [nick1811@CentOS-6 ~]$ sudo vim /etc/samba/smb.conf
      
      #======================= Global Settings =====================================
      
      [global]
      wins support = yes
      usershare path = /usr/local/samba/lib/usershares
      usershare max shares = 100
      usershare allow guests = true
      usershare owner only = false
      # Samba works on NFS-Shares
      admin users = nick1811
      strict locking = no
      oplocks = no
      acl check permissions = false
      
      
      
  • Now you can create folder shares
    • To share samba folder
    • [nick1811@centos-6 ~]$ net usershare add nick_samba /home/nick1811/samba/ "nick's samba folder" Everyone:F guest_ok=y
      
    • To unshare samba folder
    • [nick1811@centos-6 ~]$ net usershare delete nick_samba
      
  • To enable/disable samba service
  • [nick1811@centos-6 ~]$ sudo service smb start
    
    [nick1811@centos-6 ~]$ sudo service smb stop
    
    [nick1811@centos-6 ~]$ sudo service smb restart
    
  • Finally, remember to set iptables for samba
  • [nick1811@CentOS-6 ~]$ sudo vim /etc/sysconfig/iptables
    
    # SAMBA/CIFS
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
    
    [nick1811@CentOS-6 ~]$ sudo service iptables restart
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]
    iptables: Applying firewall rules:                         [  OK  ]
    
    

References: 

No comments:

Post a Comment