How to enable OS X's screen sharing (VNC) via SSH

root's picture

Ever had to connect on graphical interface remotely and find out that it's disabled and you are far away from your computer? No matter the response, I will show you below how to enable this service via SSH.

How to start, enable VNC on reboot and give rights on your user (replace PASSWORD with whatever you want):

leetmac:~ florian$ sudo  /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -clientopts -setvncpw -vncpw [color=red]PASSWORD[/color] -restart -agent -privs -all -users florian
Starting...
Activated Remote Management.
Stopped ARD Agent.
florian: Set user remote control privileges.
florian: Set user remote access.
Set the client options.
Done.

How to stop and disable VNC on reboot:

leetmac:~ florian$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off
Starting...
launchctl: Error unloading: com.apple.screensharing
Removed preference to start ARD after reboot.
florian: Set user remote access.
Done.

For more information, check the documentation of kickstart command:
leetmac:~ root# /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart --help

Please find below few examples:
Stop the Remote Management service:
kickstart -stop

Stop the Remote Management service and deactivate it so it will not start after the next computer restart:
kickstart -deactivate -stop

Restart the agent:
kickstart -restart -agent -console

Activate the Remote Management service and then restart the agent:
kickstart -activate -restart -agent -console

Activate the Remote Management service, enable access, and restart the agent:
kickstart -activate -configure -access -on -restart -agent

Disable user access:
kickstart -configure -access -off

Give admin and bob all access:
kickstart -configure -access -on -privs -all -users admin,bob

Use Directory Server accounts for authentication. Users must be a member of one of the ARD directory groups to authenticate:
kickstart -configure -clientopts -setdirlogins -dirlogins yes

Disable the Remote Management menu extra:
kickstart -configure -clientopts -setmenuextra -menuextra no

Allow access for only these users (the users must be specified in a separate command) (OS X 10.5 and later):
kickstart -configure -allowAccessFor -specifiedUsers

Allow access for all users and give all users full access (OS X 10.5 and later):
kickstart -configure -allowAccessFor -allUsers -privs -all

Start the Remote Management service (OS X 10.5 and later):
kickstart -activate

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content