Remote Admin Incantations

Quick offtopic post… here at Wooji Juice, as well as the various Macs we use for developing and testing, we also have a Mac Mini. It has performed sterling duty as our server for several years now (and hopefully will continue to do so).

The Mini doesn’t actually have a keyboard or mouse connected to it: most of the time, it’s just sitting there humming away quietly, serving up files, shuffling email around, and so on. It doesn’t actually need to be clicked or typed at, and the little admin work I need to do on it, I can usually do via Remote Login (or ssh as it’s more commonly known in the Unix world).

Sometimes, though, I do need to point and click at things; you can use Screen Sharing for this, but for security reasons I prefer to only enable it when I need to. Of course, you need to point and click at the Sharing preferences in order to switch it on, which leaves you in something of a Catch-22 situation. Not to mention that one of the most common reasons I need this, is that the Mac Mini’s just been rebooted (after yet another “reboot required” software update…) and I need to log it back in.

Here’s the thing: If you have Remote Login enabled, you can also enable Screen Sharing (or Remote Management) remotely. First, log in via ssh:

terminal command:
ssh yourmachinename.local.

(Assuming your usernames are the same on both machines; if not, stick the remote username and an @ before the machine name.)

Here’s the incantation to turn it on:

terminal command:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users YOUR_USER_NAME_HERE -privs -all -restart -agent -menu

Note that you need to replace YOUR_USER_NAME_HERE with your remote username again!

You’ll be asked for your admin password, then you’ll see some lines run past while it sets everything up. Once the terminal prompt returns, you should discover that if you select the computer in Finder, it has sprouted a Screen Sharing button.

To turn Screen Sharing back off, you can use the Sharing preferences panel via Screen Sharing itself (as soon as you click the checkbox, of course, you’ll be booted out!) but you can do this remotely too:

terminal commands:
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -agent -stop

It’s probably safe just to use the -agent -stop line, but this is the belt-and-braces approach.

Another quick tip: Once logged in, if your computer has a display attached, you can use the nifty (and free) teleport — with which you simply roll the mouse pointer off your main desktop screen and onto the remote computer’s. You can cut-and-paste between them, drag and drop files between them — it’s almost like using two displays attached to one computer, but with a whole extra computer of processing power, disk space, etc. It’s also much faster/more responsive than Screen Sharing.

But, of course you do need to log in first. Which is why I’m writing up these incantations so I can easily find them again later :-)