macでssh接続をしたときno matching key exchange method found. Their offer: diffie-hellman-group1-sha1と言われて接続できない

macssh接続を行ったときにタイトルのようなエラーが出て接続できなかったのでその時のメモ

環境

macOS Mojave バージョン10.14

エラーの内容 

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

上記のようなエラーがでて接続できません.

原因

MacOSではOpenSSH v7 を採用するようなっていくつかの暗号が無効になってしまったようです. 

Apple、macOS SierraでOpenSSH v7を採用。いくつかのレガシーな暗号が無効に。 | AAPL Ch.

解決法

サーバー側のOpenSSHのバージョンを上げたほうが良いのですが, できない状態だったので次のように解決します.

~/.ssh/config ファイルの中身に以下の設定を書き足す.

(configファイルがなければ作成して書き込んでください.)

Host 192.168.*.*
KexAlgorithms +diffie-hellman-group1-sha1

補足

自分の環境では上記の問題を解決したあとにも次のようなエラーがでて接続できませんでした.

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

これもレガシーな暗号が無効になってしまったことが原因なので, ~/.ssh/config ファイルの中の設定を変更します.

Host 192.168.*.*
KexAlgorithms +diffie-hellman-group1-sha1
Ciphers aes128-cbc # 追加

これでssh接続が可能になりました.