My linux world » srv-samba

srv-samba


Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install samba"
  4. dnf -y install samba
  5.  
  6. echo "activate samba on boot"
  7. systemctl enable smb.service
  8. systemctl enable nmb.service
  9.  
  10. echo "backup /etc/samba/smb.conf (we will change it)"
  11. mv /etc/samba/smb.conf /etc/samba/smb.conf.backup
  12.  
  13. echo "create smb.conf. Note: this example is not secure"
  14. cat > /etc/samba/smb.conf << "EOF"
  15. [global]
  16. workgroup = MYWORKGROUP
  17. netbios name = centos
  18. server string = Samba Server %v
  19.  
  20. #security mode:
  21. security = user
  22. domain logons = no
  23. encrypt passwords = yes
  24.  
  25. dns proxy = no
  26. time server = yes
  27. os level = 255
  28. log file = /var/log/samba/log.%m
  29. max log size = 50
  30. hosts allow = a.b.c.
  31. hosts deny = ALL
  32. interfaces = lo eth0
  33. bind interfaces only = Yes
  34.  
  35. # everyone can read system.
  36. [system]
  37. comment = The system files
  38. path = /
  39. public = yes
  40. writable = no
  41. create mask = 0777
  42. EOF
  43.  
  44. myprefixIP=`hostname -I | cut -d. -f1,2,3| awk '{ print $1}'`
  45. sed -i "s/a.b.c/$myprefixIP/g" /etc/samba/smb.conf
  46.  
  47. currentDevice=`nmcli d | grep connected | awk '{split($1,a,"\t"); print a[1]}'`
  48. sed -i "s/eth0/$currentDevice/g" /etc/samba/smb.conf
  49.  
  50. echo "add service smb (port 445) to firewall"
  51. firewall-cmd --permanent --add-service samba
  52. firewall-cmd --reload
  53.  
  54.  
  55. echo "restart samba"
  56. systemctl restart smb.service
  57. systemctl restart nmb.service
  58.  
  59. myip=`hostname -I`
  60. echo "Now meet you here: file://$myip"
  61.  

That’s all 🙂


Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.