VS Code Remote - SSH: Fixing the MitmPortForwardingDisabled Error
VS Code’s Remote - SSH extension sometimes refuses to connect to a host it reached just fine the day before. A banner shows up in the terminal (captured on a Chinese-language VS Code install; an English install shows the same table with English labels):
Issues were detected in the most recent Remote - SSH session.
┌────────────────────────────┬───────────────────────────────────────────────────────────┐
│ Status │ Message │
├────────────────────────────┼───────────────────────────────────────────────────────────┤
│ MitmPortForwardingDisabled │ Error: MitmPortForwardingDisabled (port forwarding is disabled) │
└────────────────────────────┴───────────────────────────────────────────────────────────┘
The underlying SSH error usually reads something like:
Could not establish connection to "your.server.example.com": Remote host key has changed, port forwarding is disabled.
Why this happens
This is an OpenSSH safety mechanism, not a VS Code bug.
The first time you connect to a server, your SSH client records the server’s public host key fingerprint in ~/.ssh/known_hosts. On every later connection it re-checks that fingerprint. If the server has since been reinstalled, had its SSH host keys regenerated, or its IP reassigned to a different machine, the fingerprint no longer matches what your client has on file.
A mismatch is exactly what a man-in-the-middle attack looks like from the client’s side — that is where the Mitm in the error name comes from. So OpenSSH tears the session down and disables port forwarding for it. Remote - SSH depends on port forwarding to talk to its server component on the remote host, which is why the extension surfaces the failure as MitmPortForwardingDisabled.
Fix 1: Remove the stale entry with ssh-keygen (recommended)
Open a terminal on your local machine (PowerShell/CMD on Windows, Terminal on macOS/Linux) and run, replacing the host with the actual IP or hostname you connect to:
ssh-keygen -R your.server.example.com
You should see Host ... found and removed. Reconnect from VS Code; it will prompt you to trust the new host key fingerprint. Answer yes and the connection works again.
Fix 2: Edit known_hosts by hand
If you prefer to clean up manually:
- Locate the
.sshfolder in your user directory —C:\Users\<you>\.ssh\known_hostson Windows,~/.ssh/known_hostson macOS/Linux. - Open
known_hostsin a text editor. - Find the line matching the IP or hostname you are connecting to, delete the entire line, and save.
- Reconnect from VS Code.
Before you delete that line
A changed host key has legitimate causes — reinstalls, regenerated keys, a cloud provider reassigning the IP to a new instance. But it can also be a real interception: ARP spoofing, DNS hijacking, or a hostile network. Deleting the old fingerprint teaches your client to trust whatever answers next, so confirm the change has a known cause first.
If you have out-of-band access to the server (a cloud console’s web terminal or VNC), print the key the server currently presents:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
Compare that fingerprint with the one VS Code shows on reconnect. If they match, accept it and move on. If they don’t, stop and investigate — you may be talking to something that is not your server.