Advertisement
xe1phix

Xe1phix-[Samba]-Notes-[.v4.2.8.].sh

Nov 10th, 2022
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.85 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3.  
  4. mkdir -p /home/samba/sambashare
  5. chown -R root:sambashare /home/samba/sambashare
  6. chmod -R 0770 /home/samba/sambashare
  7. mkdir -p /home/samba/guest
  8. chown -R nobody:nogroup /home/samba/guest
  9. chmod -R 0775 /home/samba/guest
  10.  
  11. systemctl restart nmbd.service
  12. systemctl restart smbd.service
  13.  
  14.  
  15. ## see which shares are available on a given host:
  16. smbclient -L localhost
  17.  
  18.  
  19. ## Get a list of all browsable Samba shares on the target server.
  20. smbclient -N -gL \\SambaServer 2>&1 | grep -e "Disk|" | cut -d'|' -f2
  21.  
  22.  
  23.  
  24. ##
  25. ps axuww | egrep 'PID|samba|smbd|nmbd|winbindd'
  26.  
  27.  
  28. ##
  29. pkill samba smbd nmbd winbindd
  30.  
  31.  
  32. ##
  33. samba-tool domain provision --use-rfc2307 \
  34.      --realm=CORP.EXAMPLE.COM --domain=CORP \
  35.      --server-role=dc --dns-backend=BIND9_DLZ
  36.  
  37.  
  38. ##
  39. samba-tool user password --user=administrator
  40.  
  41.  
  42. ## List all files opened by a particular command
  43. lsof -c dhcpd
  44.  
  45.  
  46. ## get IPs with a DHCP lease
  47. egrep "^lease" /var/lib/dhcp/db/dhcpd.leases |awk '{ print $2 }'
  48.  
  49.  
  50. ## sorted list of dhcp allocations
  51. grep ^lease /var/lib/dhcp/dhcpd.leases | cut -d ' ' -f 2 | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq
  52.  
  53.  
  54. ## follow DNS Bind named log
  55. journalctl --unit=named --follow
  56.  
  57. ##
  58. /etc/samba/smb.conf
  59. log file = /var/log/samba/%m.log
  60. logging = syslog
  61. syslog only = yes
  62. logging = systemd
  63.  
  64.  
  65. /etc/rsyslog.conf
  66. ## Log SAMBA audit information
  67.     local3.*            /var/log/samba_audit.log
  68.  
  69. ##
  70. systemctl restart rsyslog
  71.  
  72.  
  73. ##
  74. ps -axwwo user,pid,ppid,pgid,command
  75.  
  76.  
  77. ## determine theSamba server’s smbd daemon’s process ID
  78. systemctl status smb | grep PID
  79.  
  80. ## using the ss command to list any ports on which the daemon is listening:
  81. ss -utlpn | grep 6869
  82.  
  83.  
  84.  
  85. ## get the system’s hostname:
  86. nmblookup -S server-hostname
  87.  
  88.  
  89. ## use NetBIOS over TCP to look up NetBIOS names
  90. nmblookup -A
  91.  
  92.  
  93. smbstatus -d 10     (debug)
  94.  
  95.  
  96. ## becoming anActive Directory member (or joining a domain) is
  97. net mode join -U administrator-username
  98.  
  99.  
  100.  
  101. net status shares
  102. net status sessions
  103.  
  104. ## Stop or Start (Restart) a Windows service from a Linux machine
  105. net rpc -I ADDRESS -U USERNAME%PASSWORD service {stop|start} SVCNAME
  106.  
  107.  
  108. ##
  109. smbcontrol smbd reload-config
  110.  
  111.  
  112. ## Mount a Windows share on the local network (Ubuntu) with user rights and use a specific samba user
  113. mount -t cifs -o user,username="samba username" //$ip_or_host/$sharename /mnt
  114.  
  115. mount -t cifs -o credentials=/path/to/credenials //hostname/sharename /mount/point
  116. mount -t cifs -o username=[USER] //[IP_SERVER]/[USER_FOLDER] /[DIR]/[USER]
  117.  
  118.  
  119.  
  120.  
  121. ## Unmount all mounted SAMBA/Windows shares
  122. umount -t smbfs
  123. mount|grep -e '//'|cut -d ' ' -f3| xargs -I {} umount {}
  124.  
  125.  
  126. ## List all Samba user name
  127. pdbedit -w -L | awk -F":" '{print $1}'
  128.  
  129.  
  130.  
  131. ##
  132. alias nbtstat='nmblookup -S -U <server> -R'
  133.  
  134.  
  135. ## RESTORE - SERVER
  136. tdbdump passdb.tdb.bak > passdb.dumpfile
  137. tdbrestore passdb.tdb < passdb.dumpfile
  138.  
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement