From 09f6c9f290ddc0f870bd24d2a4d77a0618979c8d Mon Sep 17 00:00:00 2001 From: jeanGaston Date: Mon, 30 Oct 2023 18:50:34 +0100 Subject: [PATCH] Update ad-join-script.sh Adding hostname changing and a bit of textual info during execution --- ad-join-script.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ad-join-script.sh b/ad-join-script.sh index 6bd44ef..fad871a 100644 --- a/ad-join-script.sh +++ b/ad-join-script.sh @@ -1,5 +1,12 @@ #!/bin/bash +# Enable verbose output +set -x + +# Prompt the user for the hostname +read -p "Enter the hostname for the server: " hostname +echo + # Prompt the user for the necessary information read -p "Administrator username (AdminUser): " admin_user read -s -p "Administrator password: " admin_password @@ -16,28 +23,43 @@ while true; do fi done +# Display hostname change information +echo "Changing the hostname to: $hostname.$domain_name" + +# Change the hostname +hostnamectl set-hostname $hostname +echo "$hostname.$domain_name" | sudo tee -a /etc/hostname + # Change the DNS server settings in /etc/resolv.conf +echo "Changing DNS server to: $dns_server" echo "nameserver $dns_server" | sudo tee /etc/resolv.conf # Install the necessary packages +echo "Installing required packages..." apt -y install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit # Discover the domain +echo "Discovering the domain..." realm discover $domain_name # Join the domain using the provided information -echo $admin_password | realm join -U $admin_user $domain_name +echo "Joining the domain..." +echo $admin_password | realm join -U $admin_user $domain_name --computer-ou=OU=Computers,DC=example,DC=com # Modify the sssd.conf configuration +echo "Modifying sssd.conf..." sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf # Restart the SSSD service +echo "Restarting the SSSD service..." systemctl restart sssd # Add the user to the sudoers file +echo "Adding the user to the sudoers file..." echo "$admin_user ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers # Verify successful domain join by looking up the user +echo "Verifying domain join..." if id $admin_user; then echo "The server has been successfully joined to the Active Directory domain." else