FreeIPA 設定檔導致的 SSH 錯誤

前言

事情要說回到前兩週更新 Proxmox 集群時,在更新完成兩個節點後,有使用者回報發生無法打開虛擬機的錯誤,仔細查看後發現是 SSH 的錯誤,在其他節點的 Web UI 開啟另一個節點上虛擬機的 Console 會發生錯誤,不過當時猜測可能是因為集群沒有完整更新完成,部分節點仍停留在 PVE 8,因此暫時忽略。

在徹底更新完成整個集群後,又發現了有關 Migrate 的錯誤,遷移虛擬機時通通發生以下錯誤。

1
2
3
4
5
6
7
8
******************************************************************************
Your system is configured to use the obsolete tool sss_ssh_knownhostsproxy.
Please read the sss_ssh_knownhosts(1) man page to learn about its replacement.
******************************************************************************

Connection closed by UNKNOWN port 65535

TASK ERROR: command '/usr/bin/ssh -e none -o 'BatchMode=yes' -o 'HostKeyAlias=xxx' -o 'UserKnownHostsFile=/etc/pve/nodes/xxx/ssh_known_hosts' -o 'GlobalKnownHostsFile=none' root@10.x.x.x pvecm mtunnel -migration_network 10.x.x.x/24 -get_migration_ip' failed: exit code 255

問題

其實這個錯誤相當好解決。只要把上面兩排星號間的錯誤訊息在丟到 Google,就能立刻找到兩篇文章,一篇是對 SSSD 的 Bug report[1],一篇是抱怨 Debian 上的 FreeIPA 會導致更新後 SSH 出錯[2],這兩篇文章都提到了是sss_ssh_knownhostsproxy導致的問題。

在 SSSD 更新後(Proxmox/Debian 大版本更新),sss_ssh_knownhostsproxy這個指令被廢棄,轉向使用新的指令sss_ssh_knownhosts,但舊的指令仍然存在,只會回傳錯誤。

1
2
3
4
******************************************************************************
Your system is configured to use the obsolete tool sss_ssh_knownhostsproxy.
Please read the sss_ssh_knownhosts(1) man page to learn about its replacement.
******************************************************************************

之所以會使用到sss_ssh_knownhostsproxy指令是因為在ipa-client-install時會建立設定檔/etc/ssh/sshd_config.d/04-ipa.conf,其中就包括了透過 SSSD 查詢 ssh knownhost 的設定,參考 FreeIPA 設定與客戶端安裝過程 - 使用 FreeIPA-Client 驗證

1
2
3
4
5
6
7
8
9
10
11
# IPA-related configuration changes to ssh_config
#
PubkeyAuthentication yes
# disabled by ipa-client update
# GlobalKnownHostsFile /var/lib/sss/pubconf/known_hosts
#VerifyHostKeyDNS yes

# assumes that if a user does not have shell (/sbin/nologin),
# this will return nonzero exit code and proxy command will be ignored
Match exec true
ProxyCommand /usr/bin/sss_ssh_knownhostsproxy -p %p %h

解決

解決方法其實很簡單,就是把ProxyCommand的設定修正一下和註解GlobalKnownHostsFile就好

1
2
3
4
5
6
7
# sed -E --in-place=.orig 's/^(GlobalKnownHostsFile 
\/var\/lib\/sss\/pubconf\/known_hosts)$/# disabled by ipa-client
update\n# \1/' /etc/ssh/sshd_config.d/04-ipa.conf
# sed -E --in-place=.orig 's/(ProxyCommand
\/usr\/bin\/sss_ssh_knownhostsproxy -p \%p \%h)/# replaced by ipa-client
update\n KnownHostsCommand \/usr\/bin\/sss_ssh_knownhosts \%H/'
/etc/ssh/sshd_config.d/04-ipa.conf

修正後的內容如下

1
2
3
4
5
6
7
8
9
10
11
12
# IPA-related configuration changes to ssh_config
#
PubkeyAuthentication yes
# disabled by ipa-client update
# GlobalKnownHostsFile /var/lib/sss/pubconf/known_hosts
#VerifyHostKeyDNS yes

# assumes that if a user does not have shell (/sbin/nologin),
# this will return nonzero exit code and proxy command will be ignored
Match exec true
# replaced by ipa-client update
KnownHostsCommand /usr/bin/sss_ssh_knownhosts %H

深入

雖然問題很容易解決,不過我很好奇,為什麼更新會導致這種錯誤。

在第二篇文章中,有提到 #9536(FreeIPA 的 Issue 9536),並且4.12的 release note也有提到這個 Issue,而且特別說明在更新版本時會通過一種機制自動升級設定檔。

Deprecated sss_ssh_knownhostsproxy in favor of sss_ssh_knownhosts. With this update, if /usr/bin/sss_ssh_knownhosts is present, it will be used instead of /usr/bin/sss_ssh_knownhostsproxy. We implemented a mechanism to apply this change when upgrading from older versions, and downgrading from newer versions.

我翻了一下 Issue 的內容,找到了 a41e5e2 這個 Commit,在這個 Commit 中修改了 spec file,增加了判斷 SSSD 是否升級的邏輯,如果升級了,就把設定檔用sed取代成新的樣式,反之取代成舊的樣式。

但問題是, spec file 是 RPM 打包時的設定檔案之一,它只適用於 RPM-based system,而 Proxmox/Debian 是 DEB-based system, DEB 是用 deb control file 來做這種設定,但是打包時卻沒有將這部份的邏輯增加到 deb control 中。

DEB 的設定結構

目前先提了一個 Debian Bug report,看之後打包人員是否會納入修正吧,#1111396

參考


FreeIPA 設定檔導致的 SSH 錯誤
https://www.zenwen.eu.org/freeipa-ssh-error-on-debian/
作者
Zen Wen
發布於
2025年8月29日
許可協議