| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/bin/bash
- # Load configuration file
- source config.sh
- # Load password file
- read -r ADMINUSER ADMINPASS < adm.txt
- # Set the hostname
- sudo hostnamectl set-hostname $NEW_HOSTNAME
- # Update /etc/hosts
- echo "127.0.0.1 localhost" | sudo tee /etc/hosts
- echo "$NEW_HOSTNAME $(hostname -I | cut -d' ' -f1)" | sudo tee -a /etc/hosts
- # Update /etc/hostname
- echo $NEW_HOSTNAME | sudo tee /etc/hostname
- # Update and install required packages
- sudo apt update
- sudo apt install -y sudo apt -y install realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
- # Join the domain
- sudo realm join -U $ADMINUSER $DOMAIN
- # Configure SSSD
- sudo sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
- sudo systemctl restart sssd
- # Allow domain users to log in to the machine
- sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
- sudo systemctl restart sshd
- # Configure PAM to create home directories for domain users on first login
- sudo bash -c "cat >> /usr/share/pam-configs/mkhomedir" << EOL
- Name: Activate mkhomedir
- Default: yes
- Priority: 900
- Session-Type: Additional
- Session:
- required pam_mkhomedir.so umask=0077 skel=/etc/skel
- EOL
- # Enable the mkhomedir PAM module
- sudo pam-auth-update --force
- # Set permissions for the home directories
- sudo chmod 0700 /home/*
- # Install any additional software
- sudo apt install -y <software-package-name>
- # Query user and print message
- id chagood && echo "Successfully queried Active Directory for user chagood"
|