/build/static/layout/Breadcrumb_cap_w.png

Script to enable SSH, rename computer, and join AD Domain on Mac (Mountain Lion)

Here is a script we are using as a post-installation task to enable SSH, set the computer name, and then join the computer to our Active Directory managed domain. 

Note: the template we are using to name our Macs is the letter 'M' followed by the serial number. You can edit the script to take out the M before "$SN", or you can append anything else you'd like onto it, such as an asset take or location. 

Please set HOST, DOMAIN, ADUSERNAME, and ADPASS to match the information for your domain. ADUSERNAME and ADPASS should be a user with sufficient privilages to add the computers to the domain. 

#!/bin/bash 

HOST="ADserver.domain.com"

DOMAIN="domain.com"

ADUSERNAME="admin"

ADPASS="secretpassword"

 

# Enable SSH

echo "Enabling SSH"

systemsetup -setremotelogin on

launchctl load -w /System/Library/LaunchDaemons/ssh.plist

 

# Find the serial number

SN=$(system_profiler | grep 'r (system)' | tail -1 | awk '{print $4}')

echo "Serial Number: $SN"

 

# Set HostName, LocalHostName, and ComputerName to M$SN

echo "Setting computer names to M$SN"

scutil --set HostName M$SN

scutil --set LocalHostName M$SN

scutil --set ComputerName M$SN

 

# Add computer to Active Directory

echo "Adding computer to Active Directory"

dsconfigad -preferred $HOST -domain $DOMAIN -u $ADUSERNAME -p $ADPASS


Comments

  • Nice Script Thx. is it Posible To generate Computername say MMAC*** Where *** are 3 unique numbers of Mac Adress ? And Put Computer accounts in a other OU ? - Raoul.tjin 10 years ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ