UbuntuJoinDomain.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. set -e
  3. # run dpkg-reconfigure unattended-upgrades and answer no unattended
  4. echo "Running dpkg-reconfigure unattended-upgrades..."
  5. echo "unattended-upgrades unattended-upgrades/enable_auto_updates boolean false" | sudo debconf-set-selections
  6. sudo dpkg-reconfigure -f noninteractive unattended-upgrades
  7. # mark linux-image-generic and linux-headers-generic as held back
  8. echo "Marking linux-image-generic and linux-headers-generic as held back..."
  9. sudo apt-mark hold linux-image-generic linux-headers-generic
  10. # upgrade the system
  11. echo "Upgrading the system..."
  12. sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
  13. # Update and install required packages for Active Directory
  14. sudo DEBIAN_FRONTEND=noninteractive apt update
  15. sudo DEBIAN_FRONTEND=noninteractive apt install -y realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
  16. # Install any additional software
  17. # Required packages for Ninja
  18. sudo DEBIAN_FRONTEND=noninteractive apt install -y net-tools network-manager policycoreutils
  19. # Load configuration file
  20. source config.sh
  21. # Set the username and password
  22. ADMINUSER=$ADMIN_USER
  23. #ADMINPASS=$ADMIN_PASSWORD
  24. # Set the hostname
  25. sudo hostnamectl set-hostname "$NEW_HOSTNAME"
  26. # Set /etc/host
  27. echo "127.0.0.1 localhost" | sudo tee /etc/hosts
  28. echo "$(hostname -I | cut -d' ' -f1) $HOST $NEW_HOSTNAME" | sudo tee -a /etc/hosts
  29. # Update and install required packages
  30. #sudo apt update
  31. #sudo apt install -y realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
  32. # Join the domain
  33. #echo "$ADMINPASS" | sudo -S realm join --user="$ADMINUSER" --computer-ou="$OU" "$DOMAIN"
  34. echo "Joining the domain..."
  35. sudo -S realm join --user="$ADMINUSER" --computer-ou="$OU" "$DOMAIN"
  36. #work in progress - --computer-desc="$COMPUTER_DESC"
  37. # Configure PAM to create home directories for domain users on first login
  38. sudo bash -c "cat >> /usr/share/pam-configs/mkhomedir" << EOL
  39. Name: Activate mkhomedir
  40. Default: yes
  41. Priority: 900
  42. Session-Type: Additional
  43. Session:
  44. required pam_mkhomedir.so umask=0077 skel=/etc/skel
  45. EOL
  46. # Enable the mkhomedir PAM module
  47. sudo pam-auth-update --enable mkhomedir
  48. # Set permissions for the home directories
  49. sudo chmod 0700 /home/*
  50. # Configure SSSD
  51. sudo sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
  52. # Deny login to all users
  53. sudo realm deny --all
  54. # Allow login to domain groups
  55. sudo realm permit -g "Domain Admins"
  56. sudo realm permit -g "Access - Admin - All Servers"
  57. sudo realm permit -g "Access - Admin - $HOST"
  58. sudo realm permit -g "Access - Admin - All Linux Servers"
  59. # Set up sudoers file
  60. echo "%Domain\ Admins ALL=(ALL:ALL) ALL" | sudo tee /etc/sudoers.d/LocalAdmins > /dev/null
  61. echo "%Access\ -\ Admin\ -\ All\ Servers ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
  62. echo "%Access\ -\ Admin\ -\ All\ Linux\ Servers ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
  63. echo "%Access\ -\ Admin\ -\ $HOST ALL=(ALL) ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
  64. echo "Ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/LocalAdmins > /dev/null
  65. # Set Timezone to Eastern
  66. echo "Seting the Timezone..."
  67. sudo timedatectl set-timezone America/New_York
  68. # copy file from SCP server to local system
  69. # sudo scp -r anonymous@ptiwa001:ninja-agent.deb /home/coadmin/
  70. echo "Installing Ninja..."
  71. curl -o ninja-agent.deb https://app.ninjarmm.com/agent/installer/e99519fc-b76e-4c50-b5ff-ef68db95b032/serverslinuxmainoffice-5.6.7925-installer-x86-64.deb
  72. # install Ninja
  73. sudo dpkg -i ninja-agent.deb
  74. # copy file from SCP server to local system
  75. #sudo scp -r anonymous@ptiwa001:falcon-sensor_6.46.0-14306.deb /home/coadmin/
  76. # Install CrowdStrike Falcon
  77. echo "Installing Falcon Sensor..."
  78. sudo export FALCON_CLIENT_ID="58f632f6b11c43f48864c9043ec8428d"
  79. sudo export FALCON_CLIENT_SECRET="8VrQZaLfAHgJNpED0627tyeu9oGbcwWP51mxYk34"
  80. sudo export FALCON_CID="D0511099B3FF494D8B87F48C4AB90201-56"
  81. sudo export FALCON_SENSOR_VERSION_DECREMENT="1"
  82. curl -L https://raw.githubusercontent.com/crowdstrike/falcon-linux-install-bash/main/falcon-linux-deploy.sh | sudo bash
  83. # install package using dpkg
  84. # sudo dpkg -i falcon-sensor_6.46.0-14306.deb
  85. # Run the additional command
  86. # sudo /opt/CrowdStrike/falconctl -s --cid=D0511099B3FF494D8B87F48C4AB90201-56
  87. # Remove packages that are not required
  88. echo "Removing old packages..."
  89. sudo apt autoremove -y
  90. # Configure syslog server
  91. echo "Configuring syslog server..."
  92. echo 'remote host is: dcpi-siem 10.200.24.51:514' | sudo tee -a /etc/rsyslog.conf
  93. echo '*.* @@10.200.24.51:514' | sudo tee -a /etc/rsyslog.conf
  94. # Start/Restart Services
  95. echo "Restarting system services..."
  96. sudo systemctl restart sssd
  97. sudo systemctl start ninjarmm-agent.service
  98. sudo systemctl start falcon-sensor
  99. sudo systemctl restart rsyslog
  100. # check the status of the services
  101. sudo systemctl | grep -E 'falcon-sensor|ninjarmm-agent|sssd.service'
  102. # Query user and print message
  103. id chagood && echo "Successfully queried Active Directory for user chagood"
  104. # Check if reboot is required
  105. if [ -f /var/run/reboot-required ]; then
  106. echo -e "\033[31mA reboot is required.\033[0m"
  107. else
  108. echo -e "\033[32mReboot not required.\033[0m"
  109. fi