enable & disable SSH via Script

Recently in the business we’ve had to enable SSH so we can remotely change hostname information and verify Active Directory binding.

The below script was created so that the administrator accounts would have SSH access into the device.

The same commands can be run on the actual machine via terminal, as well as enabling in the GUI – System Preferences.

#!/bin/sh
# The following script will enable SSH on macOS
#
#
#
sudo systemsetup -setremotelogin on
launchctl load -w /System/Library/LaunchDaemons/ssh.plist

To disable SSH use the following script instead:

#!/bin/sh
# The following script will enable SSH on macOS
#
#
#
sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
sudo systemsetup -setremotelogin off

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s