Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $CentOS_FQDN = 'L152L-SMB.L152L-ROOT.COM'
  2.  
  3. $DC_Name = 'L152L-DC1'
  4. $DC_IP = '10.10.152.210'
  5. $Centos_IP = '10.10.152.216'
  6.  
  7. $CentOS_password = 'p@ssword1'
  8.  
  9. $domain_e = ($CentOS_FQDN).Split(".")
  10. $netbios_dc = $domain_e[$domain_e.Count-1]
  11. $netbios =  $domain_e[$domain_e.Count-2]
  12.  
  13. #set hostname
  14. $hostname_command = {echo  "{0}   {1}   {2}" >> /etc/hosts ; hostname "{3}" } -f $Centos_IP,$($domain_e[0]),$CentOS_FQDN,$domain_e[0]
  15. $create_dir = "mkdir -p /samba/testshare; chmod 0770 /samba/testshare;chgrp 'Domain users' /samba/testshare; semanage fcontext -a -t samba_share_t /samba/* ; restorecon -R -v /samba"
  16. echo 'y' | C:\plink.exe -ssh $Centos_IP -l root -pw p@ssword1  exit
  17.  
  18. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password  "$hostname_command"
  19.  
  20. # update resolv.conf
  21. $resolv = "$'domain $($netbios+'.'+$netbios_dc)\nsearch $($netbios+'.'+$netbios_dc)\nnameserver $DC_IP\nnameserver 172.16.10.4\nnameserver 172.16.10.5\n'"
  22. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password  "echo -e `"$resolv`" > /etc/resolv.conf"
  23.  
  24. # add cron sync job
  25. $crontab = {crontab -l >/tmp/cronfile ; echo '0 */4 * * * /usr/sbin/ntpdate 172.16.10.4 >/dev/null 2>&1' >> /tmp/cronfile ; crontab /tmp/cronfile}
  26. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password  "$crontab"
  27.  
  28. #install packages
  29. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password  "yum install -y ntpdate samba samba-client samba-winbind krb5-workstation policycoreutils-python --nogpgcheck"
  30.  
  31. #sync time
  32. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password  "ntpdate 172.16.10.4"
  33.  
  34. $smb_conf = '[global]
  35.     workgroup = {0}
  36.     security = ads
  37.     realm = {0}.{1}
  38.    socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
  39.    use sendfile = true
  40.     idmap config * : backend = tdb
  41.     idmap config * : range = 100000-299999
  42.     idmap config {0} : backend = rid
  43.     idmap config {0} : range = 10000-99999
  44.     winbind separator = +
  45.     winbind enum users = yes
  46.     winbind enum groups = yes
  47.     winbind use default domain = yes
  48.     winbind refresh tickets = yes
  49.     restrict anonymous = 2
  50.     log file = /var/log/samba/log.%m
  51.     max log size = 50  
  52. #============================ Share Definitions ==============================
  53. [testshare]
  54.     comment = Test share
  55.     path = /samba/testshare
  56.     read only = no
  57.     force group = "Domain Users"
  58.     directory mask = 0770
  59.     force directory mode = 0770
  60.     create mask = 0660
  61.     force create mode = 0660
  62.     access based share enum = yes
  63.     hide unreadable = yes
  64. ' -f $netbios,$netbios_dc
  65. $smb_conf_command = { echo -e '{0}' > /tmp/test } -f $smb_conf
  66.  
  67. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "$smb_conf_command"
  68.  
  69. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "cat /tmp/test > /etc/samba/smb.conf"
  70.  
  71. $krb5_conf  = "[logging]
  72.  default = FILE:/var/log/krb5libs.log
  73.  kdc = FILE:/var/log/krb5kdc.log
  74.  admin_server = FILE:/var/log/kadmind.log
  75.  
  76. [libdefaults]
  77.  default_realm = $netbios.$netbios_dc
  78.  ticket_lifetime = 24h
  79.  forwardable = yes
  80.  
  81. [appdefaults]
  82.  pam = {
  83.    debug = false
  84.    ticket_lifetime = 36000
  85.    renew_lifetime = 36000
  86.    forwardable = true
  87.    krb4_convert = false
  88.  }
  89.  "
  90. $krb5_conf_command = { echo -e '{0}' > /etc/krb5.conf } -f $krb5_conf
  91. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "$krb5_conf_command"
  92.  
  93. #winbind passwords
  94. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "sed -i '/passwd:     files/c\passwd:     files winbind' /etc/nsswitch.conf"
  95. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "sed -i '/group:      files/c\group:      files winbind' /etc/nsswitch.conf"
  96.  
  97. #Join Domain
  98. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "net ads join -U administrator%p@ssword1 -S $($DC_Name+'.'+$netbios+'.'+$netbios_dc)"
  99.  
  100. #restart services
  101. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "service winbind restart; service nmb restart; service smb restart"
  102.  
  103. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "$create_dir"
  104.  
  105. #clear IPtables
  106. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "iptables -F; service iptables save;"
  107.  
  108. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "service winbind restart; service nmb restart; service smb restart"
  109. C:\plink.exe -ssh $Centos_IP -l root -pw $CentOS_password "chkconfig winbind on; chkconfig nmb on; chkconfig smb on"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement