SSH into a server from macOS
A verified, step-by-step path to opening a secure shell on a remote server using the tools already on your Mac.
What this covers
Connecting to a server over SSH uses the client built into macOS. This guide walks through the checks worth doing first — confirming the server accepts SSH, verifying its host key, and optionally saving your key passphrase — then the actual login.
Make sure the server accepts SSH connections
If the machine you're connecting to is also a Mac, Remote Login must be enabled there before any ssh attempt will succeed. An administrator on the server can turn it on with systemsetup. You can tell it worked by seeing the server appear in System Settings under Sharing, or by simply trying the connection in the next step.
systemsetup -setremotelogin enables the macOS SSH server so you can log in from another machine.
$ sudo systemsetup -setremotelogin on▾ Undo
$ sudo systemsetup -setremotelogin offVerify the host key before trusting the server
On first connect, ssh asks you to trust the server's host key. Computing the fingerprint beforehand with ssh-keygen lets you confirm you're connecting to the right machine, not an impostor. It worked when the fingerprint shown by ssh-keygen matches what the server administrator gave you.
Compute the SHA256 fingerprint of any SSH public key or remote host key for verification.
$ ssh-keygen -lf ~/.ssh/id_ed25519.pub
# Fingerprint of a remote host key:
ssh-keyscan example.com | ssh-keygen -lf -Store your SSH passphrase in the Keychain (optional)
If you log in with a key rather than a password, adding its passphrase to the macOS Keychain means ssh-agent loads it automatically, so you won't be prompted for it every time. You'll know it worked when a later ssh connection completes without asking for the passphrase.
Apple's ssh-add has a macOS-specific flag, --apple-use-keychain, that remembers passphrases so ssh-agent can load keys automatically.
$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519▾ Undo
$ ssh-add -D && ssh-add --apple-use-keychain ~/.ssh/id_ed25519 (re-add without passphrase by regenerating the key)Connect with ssh
This is the core step: macOS ships with an ssh client, so no installation is needed. Replace the username and address with your server's. It worked when you see the remote machine's welcome banner and your prompt changes to the remote shell.
Use the built-in ssh client to open a secure shell on another Mac, Linux box or server.
$ ssh admin@192.168.1.20How to confirm it worked
You're connected when your Terminal prompt becomes the remote machine's shell and you see its welcome banner; run a command like hostname there to confirm you're on the server.
Undo everything
Every command above can be reverted. Run these in order to undo all of it.
$ ssh-add -D && ssh-add --apple-use-keychain ~/.ssh/id_ed25519 (re-add without passphrase by regenerating the key)
sudo systemsetup -setremotelogin offReview before running — some steps may not be independent.
Sources
- systemsetup — set system settings (macOS man page)Evidence: Documents -setremotelogin on|off, which enables or disables sshd-based Remote Login.
- launchctl — interact with launchd (macOS man page)Evidence: Background on launchd services such as sshd that Remote Login toggles.
- SSH-KEYGEN(1) — OpenBSD manualEvidence: Documents -l (fingerprint), -f (file) and reading from stdin with -.
- ssh-add(1) — macOS man pageEvidence: Documents --apple-use-keychain: the passphrase is added to the keychain and later loaded automatically by ssh-agent.
- ssh-add(1) — macOS man pageEvidence: Apple's ssh-add variant supports --apple-use-keychain (formerly -K) to persist passphrases in the macOS keychain.
- ssh(1) man pageEvidence: Man page for ssh: 'ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] … [-p port] destination [command]' with destination in user@hostname form.
- ssh(1) - OpenSSH remote login clientEvidence: Mirrors the ssh man page: ssh (SSH client) is a program for logging into a remote machine and executing commands, connecting as user@hostname.
Last verified: 2026-09-21