====== MacOS tips ======
===== Networking =====
==== Get IP address ====
$ sudo ipconfig getifaddr en1
==== Change IP address ====
$ sudo ipconfig set en1 INFORM 172.21.15.249 255.255.255.248
==== Change default gateway ====
$ sudo route delete default
$ sudo route add default 172.21.15.254
===== Users =====
==== Get user details ====
$ sudo dscl . -read /Users/bob
==== Delete a user ====
$ sudo dscl . -delete /Users/bob
==== Create a user ====
This one requires a script to wrap all the steps:
#!/bin/bash
target_user=$1
[ -z $target_user ] && echo "missing target user as first arg" && exit 1
pass=$(openssl rand -base64 12)
maxid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
userid=$((maxid+1))
dscl . -create /Users/$target_user
dscl . -create /Users/$target_user UserShell /bin/bash
dscl . -create /Users/$target_user UniqueID "$userid"
dscl . -create /Users/$target_user PrimaryGroupID 80
dscl . -create /Users/$target_user NFSHomeDirectory /Users/$target_user
dscl . -passwd /Users/$target_user $pass
dscl . -append /Groups/admin GroupMembership $target_user
cp -R /System/Library/User\ Template/English.lproj /Users/$target_user
chown -R $target_user:staff /Users/$target_user
echo "created user $target_user with id $userid and password '$pass'"
$ sudo bash create_user.sh bob
created user bob with id 502 and password 'Uv6D91hj27Tam'