bin/toggle-ssh
#!/bin/bash
if [[ "$(uname -s)" != 'Darwin' ]]; then
echo 'Sorry, this script only works on macOS'
exit 1
fi
if [[ "$(whoami)" != "root" ]]; then
echo "This script must be run by root or with sudo"
exit 1
fi
# Assumes root!
sshStatus=$(sudo systemsetup -getremotelogin | awk '{print $3}')
if [ "$sshStatus" == "On" ]; then
systemsetup -f -setremotelogin off
printf "%s" "Disabled SSH!"
elif [ "$sshStatus" == "Off" ]; then
systemsetup -f -setremotelogin on
printf "%s" "Enabled SSH!"
else
printf "Error, SSH Status was: %s" "$sshStatus"
fi