Connecting to Your Mac Server via VNC (Screen Sharing)

Connecting from macOS

For security reasons, VNC (port 5900) is not reachable from the internet. You connect through an SSH tunnel instead. You get the same Screen Sharing experience, and nothing is exposed except SSH.

This uses the SSH server built into macOS. No extra software or configuration is needed on your server.

Quick start (Mac)

Open Terminal and run:

ssh -f -o ExitOnForwardFailure=yes -L 12345:localhost:5900 your_username@your_server_ip sleep 10 && open vnc://localhost:12345

This opens the tunnel and launches Screen Sharing in one go. Log in with an admin account on your server and you are in. When you quit Screen Sharing, the tunnel closes on its own.

How it works

SSH forwards a port on your own computer (12345 in this example) to port 5900 on the server. Your VNC client connects to that local port, and all traffic runs through the encrypted SSH connection. You can pick any free local port.

Step by step

1. Create the tunnel

ssh -L 12345:localhost:5900 your_username@your_server_ip

Leave this Terminal window open. The tunnel stays up as long as the SSH session runs.

2. Connect

Open Screen Sharing and connect to:

vnc://localhost:12345

You can also enter this address in Finder via Go > Connect to Server (Cmd+K), or run open vnc://localhost:12345 in Terminal.

The quick start command explained

  • -f sends SSH to the background after you log in. Without it, SSH stays in the foreground and the command after && never runs.

  • ExitOnForwardFailure=yes makes SSH stop if port 12345 is already in use. Without it, you could end up connecting through an old tunnel that is still running.

  • sleep 10 gives Screen Sharing ten seconds to connect. SSH then stays up until you quit Screen Sharing, and exits by itself.

Persistent tunnel

If you want a tunnel without a remote command, use -N:

ssh -f -N -o ExitOnForwardFailure=yes -L 12345:localhost:5900 your_username@your_server_ip

This tunnel does not close by itself. Stop it when you are done, or before opening a new one on the same port:

pkill -f "12345:localhost:5900"

Connecting from Windows or Linux

The same tunnel works on any platform. On Windows, the ssh command is built into PowerShell:

ssh -L 12345:localhost:5900 your_username@your_server_ip

Then point a VNC client such as RealVNC Viewer or TightVNC at localhost:12345. Expect lower performance than Mac to Mac Screen Sharing. For occasional admin tasks this works fine.

Tips

Use SSH keys. With key authentication the tunnel opens without a password prompt, which is faster and more secure.

Restrict SSH to your own IP addresses. If you limit port 22 to known addresses in your firewall, your server’s management access is completely off the public internet. See Securing Your Mac Server with a Firewall. If you add your own rules for port 5900, apply them to the external interface only. The tunnel reaches Screen Sharing over loopback (lo0), so blocking 5900 there breaks it.

Keep Screen Sharing in your Dock. The app lives at /System/Library/CoreServices/Applications/Screen Sharing.app. Open it once, then right click its Dock icon and choose Options > Keep in Dock.

Need 4K? A headless Mac mini offers a limited set of resolutions because no display is connected. We connect a HDMI dummy plug by default so macOS will offer the full range, up to 4K.

Alternatives for daily use

If you work on your server for long sessions, run graphical applications or need high resolutions, a dedicated remote desktop app will feel smoother than VNC. These require installing their software on your server:

  • RustDesk: open source, self hosting, great performance, recommended

  • NoMachine: fast, good image quality, free for personal use

  • Jump Desktop: fast and secure, free for individual use

  • AnyDesk: lightweight, works well on slow connections

  • Deskin: built for remote Mac access