Page 1 of 1

[SOLVED] Package to enable SSH service on macOS

Published: November 22, 2024 - 12:40 PM
by bastien30
Good morning,

I've created a package to enable the SSH service on macOS machines (tested on ARM only); if it's useful to others, here it is:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def get_ssh_status():
    # Return True if enabled, False if disabled
    status = run(r'systemsetup -getremotelogin')
    if r'Remote Login: On' in status:
        return True
    else:
        return False

def install():
    print(r'Enabling SSH service...')
    if not get_ssh_status():
        ret = run(r'systemsetup -setremotelogin on', accept_returncodes=[0, 1])
        if ret != r'':
            print(r'Error enabling SSH service, see reason below !')
            error(ret)
        else:
            if get_ssh_status():
                print(r'SSH service successfully enabled.')
            else:
                error(r'SSH service not enabled, check workstation for misconfiguration !')
    else:
        print(r'SSH service already enabled.')

def uninstall():
    if get_ssh_status():
        ret = run(r'systemsetup -f -setremotelogin off')
        if get_ssh_status():
            print(r'Error disabling SSH service, see reason below !')
            error(ret)
        else:
            print(r'SSH service successfully disabled.')
    else:
        print(r'SSH service already disabled.')

def audit():
    if not get_ssh_status():
        print(r'SSH service not enabled, reinstalling package...')
        install()
        return "WARNING"
    else:
        print(r'SSH service enabled.')
        return "OK"
Note that by default, only users with administrator rights can connect via SSH.

Re: [SOLVED] Package to enable SSH service under macOS

Published: November 25, 2024 - 10:32 AM
by dcardon
Hi Bastien,

thanks for sharing! I've passed the message on to the packaging team who are adding it to their to-do list for the store. :-)

See you soon,

Denis