drio

Controlling a macOS box remotely

If you are a mac user you probably have had at some point a machine that you don't use as a main machine. You could sell it or trade it for your new mac. You probably won't get too much money from it (at least if you trade in). But the machine may still do great work for you. Why not to use it as a server? I wanted to do that for my macbook pro 2020 (32G i7).

As far as I know you have two options: you enable screen sharing or you enable remote control. Well, there is really one option. Remote control. You need remote control because you want to be able to do anything remotely on the machine. If you use screen sharing you will be able to take control of the machine remotely (vnc) but you won't be able to do certain tasks.

The way I remote control is by running finder, pressing cmd+k and adding the url of your server: vnc://server_here. I also have a script that I run from hammerspoon:

cat vrufus
#!/bin/bash
# vim: ft=sh:
set -e

vnc_rufus=$(cat ~drio/.config/secrets/vnc_rufus)
open vnc://$vnc_rufus@rufus

But there are a few problems we have to address.

Encrypted vault

If you have setup encryption on your hard drive then you won't be able to remotely access the machine after a reboot. The solution here is to reboot with: sudo fdesetup authrestart. This is telling OS to unlock the vault with a user (it will ask you about it) on the next reboot.

Notice you won't be able to access the machine remotely if you have a reboot that was not triggered with this method ☝🏽. You will need to login from the machine.

Sleeping

Remember to make sure your machine does not go to sleep. In system settings > battery you have the "prevent sleeping when power connected". Alternatively, run this in the console: sudo pmset -a disablesleep 1. To revert, allowing sleep again:
sudo pmset -a disablesleep 0.

Tailscale

Depending on your tailscale installation, tailscale won't be running after the reboot. You have to login to start tailscale. But I connect over the tailscale tunnel. How do we fix that? We just need to install the open source version of tailscale not the "App" version. For that follow this instructions from the tailscale friends.

The process (with my extra notes) looks like this:

  1. Stop the current version of tailscale.
  2. Make sure it does not start at login.
  3. Make sure tailscale is not aliased. (zshrc)
  4. Install go
  5. Compile tailscale: $ go install tailscale.com/cmd/tailscale{,d}@main
  6. Install tailscaled as a service: $ sudo $HOME/go/bin/tailscaled install-system-daemon
(to stop/uninstall, use: sudo tailscaled uninstall-system-daemon)
  7. tailscale up
  8. tailscale status
  9. Enjoy ✨