Strovent SystemsSign in
Reference

SSH "Corrupted MAC on input" and "message authentication code incorrect"

Corrupted MAC on input means an SSH packet failed its integrity check, either from a buggy MAC algorithm on one side or from data damaged in transit.

The connection was set up and keys were exchanged, then one side received a packet whose integrity check did not match. SSH ends the session at once rather than use data it cannot trust. The OpenSSH client shows:

Corrupted MAC on input.
ssh_dispatch_run_fatal: Connection to 192.0.2.10 port 22: message authentication code incorrect

The other side may log the same first line, and a peer can also end the session with a disconnect reason of "Packet corrupt".

What the check is

Every SSH packet after key exchange carries a MAC (message authentication code). It is computed from a secret key, the packet's sequence number and its contents. The receiver computes it again, and any difference means the packet is not what the sender sent. With an authenticated-encryption cipher such as [email protected] or [email protected], the cipher's own tag does this job and no separate MAC is chosen, but a failed tag gives the same message.

This is not an algorithm mismatch. If the two sides share no MAC at all, the connection stops before login with "no matching MAC found". See SSH "no matching key exchange method" and "no matching host key type" errors.

Two causes, two patterns

One side computes a MAC wrongly. The failure happens on every attempt, and only with one client and server pair. The best known case is the Windows OpenSSH client with [email protected] or [email protected], reported in the Win32-OpenSSH project's issue tracker. Other clients connect to the same server without trouble.

Data changed in transit. The failure is random: it can work for hours, then drop, often during a large copy with scp, sftp or rsync. TCP has its own checksum, but it is a 16-bit sum, so some damaged data passes it and only the SSH check catches it. Faulty network cards or drivers, bad cables, and firewalls or VPNs that rewrite traffic are the usual places to look.

Find out which MAC is in use

Connect with ssh -v [email protected] and look for the lines that report the chosen algorithms:

debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] compression: none

If the MAC field shows the word implicit in angle brackets, an authenticated-encryption cipher is in use, so there is no separate MAC. ssh -Q mac lists the MACs your client supports.

Fix a bad MAC algorithm

Try one connection without the suspect algorithms. A leading - removes them from the default list:

ssh -o [email protected],[email protected] [email protected]

Or name the MAC to use with -m:

ssh -m [email protected] [email protected]

If that works, make it permanent for the host in ~/.ssh/config:

Host build
    HostName host.example.com
    User user1
    MACs [email protected],[email protected]

An administrator can do the same for all clients with the MACs line in the server's sshd_config. Also check for an update to the client that has the bug.

Fix corruption in transit

Changing the MAC does not help here, because the data really is damaged. Narrow down where it happens:

  • Try another network, a wired connection, or the same network with the VPN off.
  • Copy the same large file again. If it fails at a different point each time, the path is damaging packets.
  • Ask the administrator of each host to check its network interface error counters and recent driver or firmware changes.
  • If the problem started after a firewall, VPN or load balancer change, test a path that skips that device.

Sources

Spotted a mistake? Email [email protected].