SSH and SFTP errors on macOS
One page per exact message. Read which family your error belongs to first — applying a host key fix to an authentication problem is how a working setup gets worse.
The pages below index SSH and SFTP error messages, written for people using a Mac. Each linked page takes one exact message, explains what the software is actually telling you, and ends with the command that resolves it. The pages are deliberately narrow: an error message is a precise thing, and a page that answers five of them answers none of them well.
Scope. These are errors from OpenSSH and from SFTP — the protocol layer. Errors from macFUSE and sshfs, such as System Extension Blocked or mount_macfuse: the file system is not available (2), are a different layer with different causes, and they are covered in depth on our product site's macFUSE alternatives guide rather than duplicated here.
Read the error before you fix it
SSH failures fall into two families, and telling them apart before you touch
anything saves most of the time people lose to them. The first family is about
the server proving its identity to you: messages mentioning host keys,
known_hosts, or a changed fingerprint. Nothing about your own key
is involved, and the correct response sometimes is to stop rather than to
proceed. The second family is about you proving your identity to the
server: messages mentioning publickey, authentication, or permission
denied. Here the question is which key was offered and why the server refused
it. Running the same fix from a search result against the wrong family is the
most common way to make a working setup worse.
The one command worth learning first
ssh -v you@server.example.com
A single -v turns an unhelpful one-line refusal into a
transcript of the negotiation, and it is almost always enough. In that output
you can see which configuration files were read, which host key the server
presented, which of your identities the client offered and in what order, and
where the exchange stopped. Two more vs exist and are rarely
needed. If you are about to ask anyone for help with an SSH problem, the
output of ssh -v is the thing to bring; without it, every answer
you get is a guess, including the ones you find in search results.
Error index
-
Permission denied (publickey)
The server rejected your key, or never saw it. On macOS the usual cause is the agent, not the file permissions that Linux-oriented guides start with.
-
Host key verification failed
Including the alarming REMOTE HOST IDENTIFICATION HAS CHANGED banner. When to clear the entry, and when clearing it is the wrong move.
Messages not covered yet, and the short answer for each
These do not have their own page. The one-line diagnosis is here so the page is still useful to you if yours is on this list, rather than leaving you with nothing.
| Message | What it usually means |
|---|---|
no matching host key type found |
Your client and the server share no acceptable host key algorithm. Nearly
always an old server that only offers ssh-rsa, disabled by default
since OpenSSH 8.8. See
Ed25519 or RSA for the scoped
re-enable. |
kex_exchange_identification: Connection closed by remote host |
The connection died before SSH started talking. Something in between closed it: a firewall, a rate limiter such as fail2ban after repeated failures, or a service that is not actually SSH on that port. |
Connection closed by ... port 22 immediately after connecting |
The server accepted the TCP connection and then rejected you at the SSH layer. Check whether your address has been blocked, and check the server's authentication log if you have access to it. |
Bad configuration option |
An option in ~/.ssh/config that your OpenSSH does not know.
Frequently a directive copied from a much newer or much older guide than the
version macOS ships. |
packet_write_wait: Connection to ... Broken pipe |
An idle session was cut by a NAT device or firewall. Set
ServerAliveInterval 60 in your client config so the connection
keeps proving it is alive. |
Permissions 0644 for '...' are too open |
Exactly what it says: the private key file is readable by other users.
chmod 600 on the key. Common after restoring from a backup. |
Is an SFTP error the same as an SSH error?
Sometimes, and the distinction is worth holding onto. SFTP runs as a
subsystem inside an already-established SSH connection, so every authentication
and host key error above applies to SFTP identically — if ssh
cannot connect, neither can sftp, for the same reason. Errors that
appear only under SFTP are different: permission errors on individual files,
messages about the subsystem not being available, or failures partway through a
transfer. Those are about what the server lets your user account do once you
are already logged in, or about the SFTP subsystem being disabled in
sshd_config. If your problem reproduces with plain
ssh, it is not an SFTP problem.
Disclosure. Published by OnePasswordManager Ltd, developers of SSHMount for macOS. These pages describe OpenSSH behaviour and resolve with tools already on your Mac. About this site.
Sources
Every technical claim above is checked against one of these. Where a manual page is quoted, it is the copy shipped by the vendor named, not a third-party summary of it.
- ssh(1), the manual page shipped with macOS — https://keith.github.io/xcode-man-pages/ssh.1.html
- sshd_config(5), the manual page shipped with macOS — https://keith.github.io/xcode-man-pages/sshd_config.5.html
- OpenSSH 8.8 release notes — RSA/SHA-1 disabled by default — https://www.openssh.com/txt/release-8.8