Remote access to a Mac: SSH, Screen Sharing and no exposed ports
A headless or rack-mounted Mac needs two doors: a shell and a screen. This guide shows how to switch both on, lock SSH to keys, understand Remote Management, and keep every port off the public internet.

A Mac without a display is managed from another device through two doors: a command shell and a shared screen. Both are easy to leave wider open than intended. Menu names below follow Apple's current support pages and have changed between macOS releases, so treat them as a map, not a promise.
Turn on Remote Login (SSH)
Apple's Remote Login instructions start in System Settings > General > Sharing: click the Info button beside Remote Login and switch it on. The macOS Monterey version of that page uses System Preferences and a checkbox instead.
Apple warns that remote login can make a Mac less secure, so set two options deliberately. The Allow access for menu offers all users or only listed ones; pick the list. Turn on Allow full disk access for remote users only if your workflow needs it. The panel also shows the SSH command for your Mac, a handy way to confirm the hostname.
From a terminal, systemsetup covers the same switch; the third-party SS64 reference lists these forms and says it needs admin privileges:
sudo systemsetup -getremotelogin
sudo systemsetup -setremotelogin on
Behavior may differ by macOS version, so check the current documentation before scripting it.
Use keys, then turn passwords off
Create a key on your own machine and copy the public half to the Mac:
ssh-keygen -t ed25519
ssh-copy-id [email protected]
Without ssh-copy-id, append the contents of the .pub file to ~/.ssh/authorized_keys on the Mac, a default key file in the sshd_config manual. Keep the folder and file private to their owner: with StrictModes on, sshd checks file modes and ownership before accepting a login. Confirm in a second session that the key works before changing anything else.
Then disable password logins. The sshd_config manual notes that PAM keyboard-interactive authentication usually does the job of password authentication, so with PAM you should disable PasswordAuthentication or KbdInteractiveAuthentication. Setting both to no is stricter:
PasswordAuthentication no
KbdInteractiveAuthentication no
Check whether /etc/ssh/sshd_config on your Mac has an Include line for /etc/ssh/sshd_config.d/; if so, a drop-in file there keeps your change separate. The manual says that, unless noted otherwise, the first obtained value of each keyword is used, and that Include processes files in lexical order, which, taken together, means an earlier-named file can override yours. Confirm with sudo sshd -T | grep -i authentication; the sshd manual says -T prints the effective configuration.
Screen Sharing is not Remote Management
Apple's Screen Sharing steps say to turn Remote Management off first if it is on, because the two cannot be on at the same time. Then, in the same Sharing pane, click Info beside Screen Sharing, switch it on, set Allow access for, and click Done.
Remote Management is the Apple Remote Desktop side and adds management features beyond viewing a screen: Apple's list of access privileges includes generating reports, copying items, and restarting or shutting down the Mac. Apple's Enable Remote Management page adds that on macOS 10.14 or later, Screen Sharing is view-only when the kickstart command-line tool enabled Remote Management, that from macOS 12.1 kickstart cannot enable Screen Sharing, and that an MDM solution can enable Remote Management. For simply seeing and controlling one Mac, Screen Sharing is usually enough.
One option needs care: VNC viewers may control screen with password. Turning it on requires a password for VNC viewer apps, an extra way in beside account logins, so leave it off unless you need it.
Know your ports, and keep them closed
Apple's port reference lists these services:
| Port | Protocol | Service |
|---|---|---|
| 22 | TCP | SSH, SFTP, scp |
| 5900 | TCP, UDP | Remote Framebuffer: Screen Sharing and Apple Remote Desktop |
| 3283 | TCP, UDP | Apple Remote Desktop |
For 5900, Apple cites RFC 6143, the Remote Framebuffer specification behind VNC. It calls the protocol's own password check "cryptographically weak" and not intended for untrusted networks. This guide's advice follows from that: do not forward 5900 from a router to the internet, and even with key-only SSH, avoid forwarding 22 when another route exists.
Reach the screen without exposing it
The simplest approach is an SSH tunnel, which carries Screen Sharing inside an encrypted SSH connection, an option RFC 6143 itself mentions:
ssh -N -L 5901:localhost:5900 [email protected]
Leave it running and point a VNC viewer on your computer at localhost:5901. Per the ssh manual, -L forwards a local port to a host and port on the remote side, and -N runs no remote command.
The tunnel still needs SSH to be reachable. From outside your own network, a VPN can put your devices and the Mac on one private network, so neither service needs a router port forward. Follow the chosen VPN's own documentation for setup and access control.
Firewall and a final listening check
Turn on the firewall under System Settings > Network > Firewall, then click Options to review which apps and services may accept incoming connections. Apple's firewall page notes that some unlisted apps may still get through, including system services and signed apps opened automatically by other apps; add them to the list to block them. The firewall is one layer; each service's Allow access for list matters as much.
Finally, look at what is really listening:
sudo lsof -iTCP -sTCP:LISTEN -n -P
netstat -an | grep LISTENSources
- Apple: Allow a remote computer to access your Mac
- Apple: Allow a remote computer to access your Mac (macOS Monterey version)
- Apple: Turn Mac screen sharing on or off
- Apple: Enable Remote Management
- Apple: About access privileges with Remote Desktop
- Apple: TCP and UDP ports used by Apple software products
- Apple: Block connections to your Mac with a firewall
- RFC 6143: The Remote Framebuffer Protocol
- OpenSSH sshd_config(5) manual
- OpenSSH sshd(8) manual
- OpenSSH ssh(1) manual
- SS64: systemsetup


