Advertisement
themacdweeb

OSX - Create Guest Account

Nov 1st, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.92 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Original concepts by Noel B. Alonso: https://gist.github.com/nbalonso/5696340
  4. # and Rich Trouton: https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/create_custom_guest_account
  5.  
  6. # ---------------------------------------------------------
  7. #   Set all Variables
  8. # ---------------------------------------------------------
  9.  
  10. #----- Debugging
  11. #bash -x ./[script_name.sh] for detailed script output
  12. #bash -n ./[script_name.sh] for syntax checking
  13. set -u   # verbose error checking during execution
  14.  
  15. #----- Standards
  16. script="Create-Guest-Account"
  17. now=$(date +"%m-%d-%Y %H:%M:%S")
  18.  
  19. #----- Executables
  20. mkdir=$(which mkdir)
  21. chown=$(which chown)
  22. chmod=$(which chmod)
  23. dscl=$(which dscl)
  24. security=$(which security)
  25. killall=$(which killall)
  26.  
  27. #----- Computations
  28. OSVERS=$(sw_vers -productVersion | awk -F. '{print $2}')
  29.  
  30. #----- Assignments
  31. USERNAME="Guest"            ## Account short name
  32. DISPLAYNAME="Guest User"    ## Account name displayed in System Preferences
  33. GUESTUID="600"
  34. GUESTGROUPID="600"
  35.  
  36. #----- Set Logging
  37. Log="/Library/Logs/Nike"
  38. if [ ! -d "${Log}" ];
  39. then
  40.     $mkdir $Log
  41.     $chown root:wheel $Log
  42.     $chmod 777 $Log
  43. fi
  44. exec >> "${Log}"/"${script}".log 2>&1
  45.  
  46. #----------------------------------------------------------
  47. #  Timestamp
  48. #----------------------------------------------------------
  49. echo ""
  50. echo "##### $script"
  51. echo "##### $now"
  52.  
  53. #----------------------------------------------------------
  54. #  Script
  55. #----------------------------------------------------------
  56. if [[ ${OSVERS} -ge 9 ]]; then
  57.     ${dscl} . -create /Users/"${USERNAME}"
  58.     ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_defaultLanguage en
  59.     ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_guest true
  60.     ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_writers__defaultLanguage "${USERNAME}"
  61.     ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_writers_UserCertificate "${USERNAME}"
  62.     ${dscl} . -create /Users/"${USERNAME}" AuthenticationHint ''
  63.     ${dscl} . -create /Users/"${USERNAME}" NFSHomeDirectory /Users/"${USERNAME}"
  64.  
  65.     #setting up an empty password and giving local Kerberos some time to process it
  66.     ${dscl} . -passwd /Users/"${USERNAME}" "${USERNAME}"
  67.     sleep 2
  68.  
  69.     ${dscl} . -create /Users/"${USERNAME}" Picture "/Library/User Pictures/Nature/Leaf.tif"
  70.     ${dscl} . -create /Users/"${USERNAME}" PrimaryGroupID "${GUESTGROUPID}"
  71.     ${dscl} . -create /Users/"${USERNAME}" RealName "${DISPLAYNAME}"
  72.     ${dscl} . -create /Users/"${USERNAME}" RecordName "${USERNAME}"
  73.     ${dscl} . -create /Users/"${USERNAME}" UniqueID "${GUESTUID}"
  74.     ${dscl} . -create /Users/"${USERNAME}" UserShell /bin/bash
  75.     ${security} add-generic-password -a "${USERNAME}" -s com.apple.loginwindow.guest-account -A -w "${USERNAME}" -D "application password" /Library/Keychains/System.keychain
  76.  
  77. #   Restart loginwindow
  78. #   ${killall} loginwindow
  79. else
  80.     echo "Script requires an OS of OSX 10.9 or later to function."
  81. fi
  82.  
  83. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement