在 Ubuntu 24.04 終端機使用 SSH 連線到 CentOS 6 時,你可能會遇到以下錯誤訊息:
no matching host key type found. Their offer: ssh-rsa,ssh-dss
這個問題主要是因為:
- Ubuntu 24.04 的 OpenSSH 已預設停用 ssh-rsa 及 ssh-dss(DSA)等舊式且不安全的 key type。
- CentOS 6 的 SSH server(OpenSSH 5.x)太老,只支援 ssh-rsa 與 ssh-dss。
換句話說:
👉「新」的 Ubuntu 24.04 不願意用「舊」的 CentOS 6 的金鑰方式。
本文將整理幾種實務上可用、又兼顧安全的連線方法。
✅ 方法一:一次性允許 ssh-rsa(推薦)
若 CentOS 6 支援 ssh-rsa,可用下列指令強制接受:
ssh -oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedAlgorithms=+ssh-rsa user@your-centos6-ip
✔️ 不修改系統設定
✔️ 單次使用比較安全
✅ 方法二:CentOS 6 只支援 ssh-dss (DSA) 時
若出現錯誤仍無法連上,可能對方只支援 ssh-dss:
ssh -oHostKeyAlgorithms=+ssh-dss -oPubkeyAcceptedAlgorithms=+ssh-dss user@your-centos6-ip
⚠️ ssh-dss 已極度不安全,不推薦,只在必要時臨時使用。
✅ 方法三:在 ~/.ssh/config 中永久加入例外
若需要常常連線此台 CentOS 6,可針對單一 host 放寬設定:
nano ~/.ssh/config
新增:
Host old-centos6
HostName 192.168.x.x
User user
PubkeyAcceptedAlgorithms +ssh-rsa
HostKeyAlgorithms +ssh-rsa
之後使用:
ssh old-centos6
✔️ 只針對特定主機生效
✔️ 不影響整體安全性
❌ 方法四:修改全系統設定(不建議)
sudo nano /etc/ssh/ssh_config
加入:
Host *
PubkeyAcceptedAlgorithms +ssh-rsa
HostKeyAlgorithms +ssh-rsa
⚠️ 系統所有 SSH 連線都會放寬 → 不安全,不建議。
🔍 補充:若出現 cipher 或 KEX 不匹配,也可這樣連線
舊版 CentOS 6 也可能缺乏新版 cipher,若遇到這類錯誤:
no matching cipher found
可以加:
ssh \
-oHostKeyAlgorithms=+ssh-rsa \
-oPubkeyAcceptedAlgorithms=+ssh-rsa \
-oCiphers=+aes128-cbc \
-oKexAlgorithms=+diffie-hellman-group1-sha1 \
user@ip
📌 結論:CentOS 6 SSH 過舊,連線容易出問題
CentOS 6 已在 2020 年停止維護(EOL),其內建 OpenSSH 過時、不安全,因此需要額外參數才能讓新系統連線。
建議:
- 如果能升級系統 → 最佳方案
- 若不能,至少升級其 OpenSSH(即便需要自行編譯)
- 若只是偶爾連線 → 使用本文的臨時參數即可