macOS – SSH Error ‘No Matching Exchange Method Found’

Mac SSH Error KB ID 0001245 

Problem

Certified working all the way up to macOS Ventura version 13.6
Certified working all the way up to macOS Sonoma version 14.1

I thought my RoyalTSX had broken today, I upgraded it a couple of weeks ago, and I upgraded to macOS Catalina 10.15 the other day. After this, all my SSH sessions refused to connect with this error;

 

Unable to negotiate with x.x.x.x port 22: no matching key exchange found. Their offer diffie-hellman-group1-sha1

Note: You may also see the following error;

Unable to negotiate with x.x.x.x port 22: no matching cipher found. Their offer: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc

Update: 10/04/20: With newer equipment you may see the following error;

Unable to negotiate with x.x.x.x port 22: no matching MAC found Their offer: hmac-sha2-256

Update 08/12/21: With newer Cisco equipment you may see the following error;

Unable to negotiate with x.x.x.x.1 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1

Mac SSH Error – Fix

WARNING: My usual fix for this is to edit the macs ssh_config file directly and allow the older (less secure) connection methods. It has been (correctly) pointed out, that this is the ‘least preferred‘ method, as it will allow these less sure methods for ALL SSH connections. The preferred fix, is to create a new file in your own home folder, with the connection settings for EACH SSH CONNECTION. However, I manage hundreds of firewalls. routers and switches so that method is a little unwieldy for me. But I will include it at the end of the article, for the more security conscious of you.

Not Apple’s fault to be fair, it’s OpenSSH version 7. SHA1 is weak, so support for it has been removed. Which is fine, but all my clients Cisco Firewalls, Routers, Switches are probably all using  RSA/SHA1. So until they re all updated I’m going to need to re-enable SHA1.

Open a terminal windows and execute the following;

[box]

sudo nano /etc/ssh/ssh_config
ENTER YOUR PASSWORD

[/box]

Locate the line ‘ #   MACs hmac-md5,hmac-sha1,hmac-sha2-256,umac-64@openssh.com,hmac-ripemd160′ and remove the Hash/Pound sight from the beginning, and add the extra hashing algorithm that I’ve shown above in red. 

Locate the line ‘ #   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc’ and remove the Hash/Pound sight from the beginning.

Then paste the following on the end;

HostkeyAlgorithms ssh-dss,ssh-rsa

KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1

Like so;

Mac SSH Error – Quitting Nano

To quit nano, use the Ctrl-X key combination. because you are working on has been modified since the last time you saved it, you will be prompted to save the file first. Type y to save the file.

Theres no reason to reboot, it should work straight away.

But Wait – Theres More!

It’s going to happen every time you upgrade your mac, I’ve started taking a backup of the ssh_config file, then I can just restore it back again, like so;

Backup macOS SSH Settings & Ciphers

[box]

sudo cp /etc/ssh/ssh_config /etc/ssh/ssh_config.bak

[/box]

Restore macOS SSH Settings & Ciphers

[box]

sudo rm /etc/ssh/ssh_config
sudo mv /etc/ssh/ssh_config.bak /etc/ssh/ssh_config
sudo cp /etc/ssh/ssh_config /etc/ssh/ssh_config.bak

[/box]

Mac SSH Error (The More Secure & Preferred) Fix

Using this method you will create a connection (entry) for each asset you want to connect to. This will be saved in your Home directory so if multiple people use the Mac you will need to do this for each user.

Firstly create a config file in you home directory.

[box]

sudo nano ~/ssh/config

[/box]

What this does is create a blank file that you can then create an entry for each of the assets you want to connect to. Firstly specify the hostname, then the settings for that particular asset, like so:

[box]

Host YOUR-SWITCH
User YOUR-USER
port 22
KexAlgorithms +diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
PubkeyAcceptedAlgorithms +ssh-rsa
HostkeyAlgorithms +ssh-rsa

[/box]

Note: Simply add new host entries at a new line in the SAME config file.

Related Articles, References, Credits, or External Links

NA

138 thoughts on “macOS – SSH Error ‘No Matching Exchange Method Found’

  1. I tried your work around, but it only gives me a different error. Is it possible that something more needs to be changed? Thanks

  2. It didn’t like me allowing that line. It kept throwing up a new error, though to be fair, my line was longer and looked different.

    However, putting the pound sign back and just adding that bit to the bottom worked straight away.

    Thanks for the help.

  3. Using all 3 changes will invalidate all host-keys in ‘known_hosts’.
    Only the last line was actually needed for me: KexAlgorithms diffie-hellman-group1-sha1

    With the caveat that this will force all ssh negotiations down to this less secure protocol.

    A better option is to leave /etc/ssh/ssh_config alone alltogether, and create ~/.ssh/config in your home-dir (alongside the known_hosts file)
    In ~/.ssh/config create an entry as follows for the equipment that use this key-exchange. Use as identification the name or ip you actually use on your commandline. (i.e. use ‘192.168.0.1’ or ‘firewall’ if you use ‘ssh 192.168.0.1’ or ‘ssh firewall’)

    #force key exchange:
    host 192.168.0.1 firewall.local firewall
    KexAlgorithms diffie-hellman-group1-sha1

    • This is great. I updated my Mac to 10.13.6 on 12/26/2018 and both my SSH and Sublime Text SFTP stopped working. (But my Cyberduck SFTP and Microsoft Remote Desktop continued to work.)

      Using the steps in the initial post didn’t work for me. It resulted in an alert that I would be open to a “Man in the Middle” attack and it didn’t allow me to continue.

      However, this comment helped me fix this issue. Now my SSH and Sublime Text SFTP work by creating a ~/.ssh/config file in my local user folder and adding the lines at the end of the file. (Note: 999.999.9.9 is the IP address of the remote server you want to log into.)

      # force key exchange:
      host 999.999.9.9 firewall.local firewall
      KexAlgorithms diffie-hellman-group1-sha1

    • my .ssh/config file looks like this :

      #force key exchange:
      Host 192.16.4.203
      KexAlgorithms +diffie-hellman-group1-sha1

      [It failed with the error Unable to negotiate with 192.168.0.2 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1]

  4. Thanks for the pointers. I only needed the last line in order to SSH onto my legacy Cisco switches. Also, it’s more secure to use a “+” which appends SHA1 to the usable set of algorithms, rather than using SHA1 as the default algorithm.

    KexAlgorithms +diffie-hellman-group1-sha1

  5. It only happens if the Cisco device is using IOS version 12 or older. Version 15 works fine. If you have smartnet contract with Cisco, just upgrade to the recommended software. Instead of messing around with ssh file, I just ssh to an unix server and then ssh to Cisco device.

  6. We’re going to secure ourselves right out of being able to work!

    Thanks for this – you were the first result when I Googled the problem!

    • Just adding the KexAlgorithms +diffie-hellman-group1-sha1 lines to the end of my ssh_config file worked on Mac OSX 10.12.5 (16F73)

      Thanks !

      Dan

  7. Hi,

    I had to do this to make it work:

    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
    MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
    KexAlgorithms +diffie-hellman-group1-sha1
    HostkeyAlgorithms ssh-dss,ssh-rsa

  8. This worked perfectly. Have you had any issues getting usb-c port support serial connection? unable to get my macbook pro running Sierra to support belkin usb to serial cable for connection my Cisco console cable. I tried adding drivers and using suggestions on web. None work. Love your input. Maybe you can do a post on it. – thanks Isha

    • I’ve not, I’ve got a standard USB converter (bought cheap off eBay) and I’ve never had any problems?

      P

  9. So ran into this again after upgrading to High Sierra 10.13.2…

    This time I had to add to /etc/ssh/ssh_config

    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    KexAlgorithms diffie-hellman-group1-sha1

    • Hi

      I work with 10.3.3 and had problems accessing Cisco equipment in the network. With these two lines it works. Thank you very much everyone for the contribution.

  10. Was pulling my hair out with this at work. Issue compounded by everything by being Dockerized with very minimal Linux installations. This was the missing piece of the puzzle. Thank you so much for documenting this and putting it out there!

  11. That worked great for my Adtran AOS equipment!

    I was getting an error Bad SSH2 Mac spec ‘hmac-md5,hmac-sha1,hmac-ripemd160’, so I removed hmac-ripemd60, which fixed the issue.

    sudo nano ~/.ssh/config

    #force key exchange:
    host 192.168.1.54
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    MACs hmac-md5,hmac-sha1,umac-64@openssh.com
    KexAlgorithms +diffie-hellman-group1-sha1
    HostkeyAlgorithms ssh-dss,ssh-rsa

    • Check what you are connecting ‘to’ does not have a short key length on the certificate, either 1024 or 768 is too short.

  12. Got it to work on 10.13.6 by only using these two lines:
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    HostkeyAlgorithms ssh-dss,ssh-rsa

    Having all four lines resulted in a “connection closed by host” error (too many ciphers offered).
    thanks!

  13. On MarBook Pro 2018.

    Tried the solution, but make the changes in /etc/ssh/ssh_config affect other exciting known_hosts.

    Specifying accepting additional key exchange method in ~/.ssh/config for the target seems the better way.

    Host ASAv
    Hostname myASAv.my.com
    User admin
    KexAlgorithms +diffie-hellman-group1-sha1
    IdentityFile ~/.ssh/asav-private-key

    Then you can ssh
    ssh ASAv

    • Hi, if you have one to two ASAs to connect to that fine, I’ve got literally hundreds of the things, across multiple clients 🙂

      Pete

  14. how do you use the shortcut keys at the bottom… I tried using ^6 + enter and does not work…

  15. Hi OSX 15.2 has deleted Protocol 1 even from the comments ..
    please post how to get it back.. or are the LIB’s gone for ever?

    {ssh_config content supplied but removed}

  16. Been looking for a solution to SSH to my Cisco Catalyst 3650 for about an hour.
    Your solution worked instantly! Can’t thank you enough. Great tutorial!

  17. Thank’s a lot best regards
    merci a toi pour ce fabuleux travail heureusement qu’il y a des personnes comme toi
    Merci beaucoup

  18. Cheers Mate! Many Thanks! Was about ready to chuck my mac book.
    MacOSX High Sierra October 2020 – works to ssh to my older Cisco switches.
    I could change cipher suite on all the hundreds of switches, but easier to do in in one place from my desk.

  19. Pete — cannot get this working under Catalina 10.15.7. I’ve worked this fix many times and re-checked my new config. Error I get is this:
    kex_exchange_identification: read: Connection reset by peer

  20. To make the file immutable (uneditable by anything even OS.
    Type chattr +i /etc/ssh/sshd_config

    If you need to change it just type chattr -i /etc/ssh/sshd_config

    This will stay even on OS upgrades.

    • Hi Alex,

      That’s a great tip, I’ll do that today and test it over the next upgrade!

      Pete

    • Hmmm: chattr is not recognised ‘command not found’ should we not be using chflags?

      I’ve used “sudo chflags schg /etc/ssh/sshd_config” let’s see how that works!

      Pete

  21. macOS Monterey upgrade and newer Cat9k switches. Had to use “KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1” for the last line to get everything working.

  22. Worked for me to fix SSH problems after upgrade to Monterey.
    Although I also had to comment out old host SHA fingerprints in ssh/known_hosts.

    • I’m on Sonoma and this solution is not working:

      ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c aes256-ctr user@192.168.4.203

      ssh: connect to host 192.168.4.181 port 22: Operation timed out

  23. Outstanding… worked like a charm. I just added a key for diffie-hellman-group14-sha1, because that was also popping up for me as well. Thank you very much!

  24. This worked great for getting SSH working thank you!
    What I am still having trouble with is SCP on the same router from the same computer that can SSH. Any thoughts?

    • Your SCP client might not ee using the same Crypto as the MacOS host – Try a different SCP software.

  25. Ran into this issue when my company replaced my Macbook for a new one running Monteray. Happy to say this fix is still working in March 2022. Thanks a lot for this!

  26. Worked perfectly allowing me to access an old ReadyNAS NAS storage device which I could no l longer get to after upgrading to MacOS Monterey. Thank you so much!

  27. Note this still works with Monterey 12.3.1; I had the .bak file from a previous update so just copied it and it worked immediately; no reboot necessary.

  28. Hi Edward,

    Agreed, next time I have to do this I’ll update the article. Thanks for the feedback!

    P

  29. Hi, thanks for the good article and all the comments and insights.

    I’m on Ventura 13.1 and needed to use the following in my ~/.ssh/config file

    host 192.168.1.150
    HostkeyAlgorithms ssh-dss,ssh-rsa
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1

    • Thanks Bart! I just updated to Ventura and encountered this problem trying to ssh to my old Cisco router and switch.

      Your version of the fix worked perfectly for me

  30. Hi,

    I need your advice. After adding all the suggested configs there is sill an error coming up and I can’t ssh into my 3850.
    Unable to negotiate with x.x.x.x port 22: no matching host key type found. Their offer:

    Here is how my ssh_config looks like:
    # StrictHostKeyChecking ask
    # IdentityFile ~/.ssh/id_rsa
    # IdentityFile ~/.ssh/id_dsa
    # IdentityFile ~/.ssh/id_ecdsa
    # IdentityFile ~/.ssh/id_ed25519
    # Port 22
    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    MACs hmac-md5,hmac-sha1,hmac-sha2-256,umac-64@openssh.com
    # EscapeChar ~
    # Tunnel no
    # TunnelDevice any:any
    # PermitLocalCommand no
    # VisualHostKey no
    # ProxyCommand ssh -q -W %h:%p gateway.example.com
    # RekeyLimit 1G 1h
    # UserKnownHostsFile ~/.ssh/known_hosts.d/%k
    Host *
    SendEnv LANG LC_*
    HostkeyAlgorithms ssh-dss,ssh-rsa
    KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1

    and the error on the switch is:%SSH-3-NO_MATCH: No matching hostkey algorithm found: client ssh-dss,ssh-rsa server

    It is a MAC apple chip Sonoma 14.1.2 (23B92)

    Any advice is very welcome

  31. Fixed in the local ssh config file (~/.ssh/config) with the following settings:

    Host *YOUR_SWITCH*
    HostName *YOUR_SWITCH*
    User *YOUR_USER*
    port 22
    KexAlgorithms +diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa

    • No need to remove the Hash/Pound sight for following:
      #KexAlgorithms +diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
      #Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc

      Just add following two lines:
      PubkeyAcceptedAlgorithms +ssh-rsa
      HostkeyAlgorithms +ssh-rsa

      Confirmed with Ubuntu ssh client.

  32. For Royal TSX users specifically, I found a much simpler way to “solve” this issue. Open the connection’s properties page and go to Advanced > SSH > Advanced > Additional SSH Options and copy/paste in the following line

    -o KexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 -o Ciphers=+aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc -o PubkeyAcceptedAlgorithms=+ssh-rsa -o HostkeyAlgorithms=+ssh-rsa

    The format of that page is weird in that it looks like you have to check the “Disable pseudo-terminal allocation” checkbox above it enable the “Additional SSH Options” field but I’ve verified it is not required.

    No editing conf files needed and you can enable this on a per connection basis right from within the Royal TSX app. Easy Peezy.

    • This looks like an outstanding Tip! I use RoyalTSX myself so I’ll give it a whirl after my next upgrade. Thanks for posting.

      P

  33. Insane that in 2024, on IOS-XE 17.2.3, that Cisco still doesn’t support anything more secure than SHA1….

Leave a Reply

Your email address will not be published. Required fields are marked *