# Harden Security on a Remote Mac Desktop Session

Canonical: https://figment.so/blog/mac-remote-desktop-security-hardening

Block port 5900 with pf, reach Screen Sharing only through an SSH local forward, switch sshd to key-only login, and confirm with nmap. Every Figment plan includes SSH.

**Close port 5900, reach Screen Sharing only through an SSH local forward, and switch sshd to key-only login.** This runbook does the three steps in that order and ends with an nmap check you can run from outside. It applies to any Mac you can open a shell on, and every Figment plan includes SSH and administrator access to your own Mac or VM. Figment makes raw VNC reachable only through an authenticated, encrypted connection and never exposes it directly. The settings below still matter, because you control what runs on your own Mac.

## What does an open VNC port expose?

macOS Screen Sharing listens on TCP 5900. The classic VNC authentication exchange is a short DES challenge-response and the payload itself is not encrypted, so a password alone is not an acceptable defence for a host reachable from arbitrary IPs. An attacker who gets in has the logged-in user's graphical session: Finder, Keychain Access, browser cookies, everything. Treat 5900 like a database port and never make it directly public.

## How do I block port 5900 with pf?

Create a pf anchor so your rule is isolated from the default `/etc/pf.conf`. macOS ships with pf from OpenBSD.

```bash
sudo mkdir -p /etc/pf.anchors
sudo tee /etc/pf.anchors/vnc-block > /dev/null << 'EOF'
block in quick proto tcp from any to any port 5900
pass  in quick on lo0 proto tcp to any port 5900
EOF
```

Reference the anchor from `/etc/pf.conf`:

```bash
echo 'anchor "vnc-block"' | sudo tee -a /etc/pf.conf
echo 'load anchor "vnc-block" from "/etc/pf.anchors/vnc-block"' | sudo tee -a /etc/pf.conf
```

Enable pf and load the rules:

```bash
sudo pfctl -ef /etc/pf.conf
sudo pfctl -s rules | grep 5900
```

macOS does not re-enable pf automatically on reboot. Add a LaunchDaemon at `/Library/LaunchDaemons/com.example.pf-vnc-block.plist` that runs `/sbin/pfctl -e -f /etc/pf.conf` with `RunAtLoad` set, then `sudo launchctl bootstrap system` it. Without that step the block disappears after the next restart and 5900 is open again.

## How do I reach Screen Sharing over SSH?

Forward the port through SSH. The OpenBSD [ssh(1) manual](https://man.openbsd.org/ssh) documents `-L` as forwarding "connections to the given TCP port or Unix socket on the local (client) host … to the given host and port … on the remote side." That gives you an encrypted channel on port 22 and nothing on 5900 from outside.

On your workstation:

```bash
ssh -N -L 5901:localhost:5900 you@your-mac-host
```

Point your VNC client at `localhost:5901`. For a reusable entry, add this to `~/.ssh/config`:

```
Host figment-mac
  HostName your-mac-host
  User you
  IdentityFile ~/.ssh/id_ed25519
  LocalForward 5901 localhost:5900
  ServerAliveInterval 30
```

Then run `ssh -N figment-mac` and connect VNC to `localhost:5901`. Use the host name and SSH details shown in your Figment account.

## How do I switch sshd to key-only login?

Generate a key and install it:

```bash
ssh-keygen -t ed25519 -C "mac-remote-desktop"
ssh-copy-id -i ~/.ssh/id_ed25519.pub you@your-mac-host
```

Create `/etc/ssh/sshd_config.d/10-hardening.conf` on the Mac:

```
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
AllowUsers you
```

Reload sshd and confirm from a second terminal before you close the first, so a mistake does not lock you out:

```bash
sudo launchctl kickstart -k system/com.openssh.sshd
ssh -o PreferredAuthentications=password you@your-mac-host  # must fail
ssh figment-mac true                                        # must succeed
```

If the password attempt still prompts, look for an older `/etc/ssh/sshd_config` directive overriding the drop-in.

## How do I restrict Screen Sharing to named users?

Open **System Settings > General > Sharing > Screen Sharing > Options**, set "Allow access for" to **Only these users**, and list the two or three accounts that need a desktop. Apple's [remote-login configuration page](https://support.apple.com/guide/mac-help/allow-a-remote-computer-to-access-your-mac-mchlp1066/mac) documents the same **Only these users** pattern for Remote Login and notes that the default group includes every local account, which is why "All users" is almost never what you want.

## How do I verify the change with nmap?

Run nmap from a machine outside the Mac's network. Before the pf rule is active:

```
$ nmap -Pn -p 5900 your-mac-host
PORT     STATE SERVICE
5900/tcp open  vnc
```

After the pf rule loads:

```
$ nmap -Pn -p 5900 your-mac-host
PORT     STATE    SERVICE
5900/tcp filtered vnc
```

`filtered` means pf is dropping packets silently, and `closed` is also fine. `open` means the rule did not take effect, so re-check `sudo pfctl -s info` for `Status: Enabled` and `sudo pfctl -sA` for your anchor. Also confirm SSH is still reachable:

```
$ nmap -Pn -p 22 your-mac-host
PORT   STATE SERVICE
22/tcp open  ssh
```

If 22 is filtered, a broader `block all` upstream of your anchor is swallowing SSH. Add an explicit `pass in quick proto tcp to any port 22` and reload.

## What hygiene should I keep up afterwards?

| Task | When | Command or location |
|---|---|---|
| Rotate the Screen Sharing VNC viewer password | Every 90 days | System Settings > Sharing > Screen Sharing > Options |
| Audit authorized_keys for stale entries | Monthly | `cat ~/.ssh/authorized_keys` |
| Review sshd auth attempts | Weekly | `log show --predicate 'process == "sshd"' --last 7d` |
| Confirm pf is loaded after reboots and updates | After macOS updates | `sudo pfctl -s info \| grep Status` |

After a macOS point update, pf anchors occasionally need to be reloaded even with the LaunchDaemon in place. Add the `pfctl -s info` check to your post-update runbook so a silent regression does not become a silent exposure. Credentials are per tenant, so keep your keys and Screen Sharing passwords to the people who work on your own Mac.

## Does the hardening runbook work on every Figment plan?

This runbook needs SSH, which every plan includes. The [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) ($349 a month) gives you a whole Mac on Apple silicon. The [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) ($39 a month, $6 a day) uses the browser desktop. The [Intel Mac VM](/mac-hosting#intel-vm) ($25 a month) fits Xcode 26.3 or earlier.

For an outside price check, MacStadium publishes M2.S at $109/month and M4.S at $149/month with support and a 99.99% uptime claim on its [pricing page](https://macstadium.com/pricing), and CloudMac publishes an M4/16 GB/256 GB plan at $99.99/month with a $999/year option on [cloudmac.org/pricing](https://cloudmac.org/pricing). The hardware differs: Figment's Apple Silicon VM is a virtual machine with shared vCPUs and has 4GB of memory, while Figment's Dedicated M4 Pro 48 GB is a whole Mac with 48GB. CloudMac's annual price works out to $999 ÷ 12 = $83.25 a month, against 12 × $39 = $468 a year for the Apple Silicon VM and $3,228 paid up front for 12 months of the Dedicated M4 Pro 48 GB.

## What else should I read?

- [Time-scheduled remote Mac access](/blog/mac-remote-access-time-scheduling)
- [Remote Mac display resolution guide](/blog/mac-remote-desktop-display-resolution)
- [Mac GitHub Actions self-hosted runner](/blog/mac-github-actions-self-hosted-runner)
