UbuntuJoinDomain.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # Load configuration file
  3. source config.sh
  4. # Load password file
  5. read -r ADMINUSER ADMINPASS < adm.txt
  6. # Set the hostname
  7. sudo hostnamectl set-hostname $NEW_HOSTNAME
  8. # Update /etc/hosts
  9. echo "127.0.0.1 localhost" | sudo tee /etc/hosts
  10. echo "$NEW_HOSTNAME $(hostname -I | cut -d' ' -f1)" | sudo tee -a /etc/hosts
  11. # Update /etc/hostname
  12. echo $NEW_HOSTNAME | sudo tee /etc/hostname
  13. # Update and install required packages
  14. sudo apt update
  15. sudo apt install -y sudo apt -y install realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
  16. # Join the domain
  17. sudo realm join -U $ADMINUSER $DOMAIN
  18. # Configure SSSD
  19. sudo sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
  20. sudo systemctl restart sssd
  21. # Allow domain users to log in to the machine
  22. sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
  23. sudo systemctl restart sshd
  24. # Configure PAM to create home directories for domain users on first login
  25. sudo bash -c "cat >> /usr/share/pam-configs/mkhomedir" << EOL
  26. Name: Activate mkhomedir
  27. Default: yes
  28. Priority: 900
  29. Session-Type: Additional
  30. Session:
  31. required pam_mkhomedir.so umask=0077 skel=/etc/skel
  32. EOL
  33. # Enable the mkhomedir PAM module
  34. sudo pam-auth-update --force
  35. # Set permissions for the home directories
  36. sudo chmod 0700 /home/*
  37. # Install any additional software
  38. sudo apt install -y <software-package-name>
  39. # Query user and print message
  40. id chagood && echo "Successfully queried Active Directory for user chagood"