自從使用php-syslog-ng監控日誌資訊後,經常發現一些過去會忽略的報錯資訊,目前正逐一解決中。其中一個報錯發生在,我使用密鑰通過ssh登陸到伺服器的時候,日誌資訊顯示:
Nov 19 10:32:20 printserver auth 10:32:20 pam_loginuid[9691]: set_loginuid failed opening loginuid
Nov 19 10:32:20 printserver auth 10:32:20 remote(pam_unix)[9691]: session opened for user root by (uid=0)
Nov 19 10:32:20 printserver auth 10:32:20 sshd[9689]: Accepted publickey for root from 192.168.228.244 port
1487 ssh2
一、原因
作業系統:紅旗DC Server 5.0
分析以前的系統日誌,並沒有發現類似的報錯資訊,故懷疑是最近的操作導致的。
從兩方面分析:
1、openssh-server從4.0p1升級到4.7p1;
2、使用密鑰登陸代替原來的密碼登陸方式。
先嘗試用原來的密碼方式登陸,沒有報錯;再對比其他機器上原4.0p1版的狀態,使用密鑰登陸,也沒有報錯。由於我升級openssh-server的時候,使用它內建的預設設定檔而非系統4.0p1版的配置,故覺得報錯,和配置及使用密鑰登陸都有關。
二、解決
經尋找資料後測試,可通過修改openssh-server的設定檔解決問題。
修改/etc/ssh/sshd_config為:
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no #關閉挑戰應答方式
UsePAM no #不使用PAM認證
儲存後,重啟sshd服務即可。
三、說明
上述兩個參數的說明,可從協助文檔得到註解:
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
簡單來講,就是如果開啟UsePAM,則會根據ChallengeResponseAuthentication來決定是否使用挑戰應答方式(我不知道是否這樣翻譯)。而該方式是根據密碼判斷的,不能和密鑰登陸相容,所以會出現報錯。
不同的配置,可從日誌中得到完全不同的結果:
1、關閉ChallengeResponseAuthentication和開啟UsePAM
使用密鑰登陸:
引用
Nov 19 10:57:20 printserver auth 10:57:20 sshd(pam_unix)[10322]: session opened for user root by root(uid=0)
Nov 19 10:57:20 printserver auth 10:57:20 sshd[10320]: Accepted publickey for root from 192.168.228.244 port 1595 ssh2
2、開啟ChallengeResponseAuthentication和UsePAM
使用密鑰登陸就會報錯,而使用密碼登陸是正常的:
Nov 19 12:23:33 printserver sshd(pam_unix)[24454]: session opened for user root by root(uid=0)
四、其他
在Google的時候,發現有另外一種解決方案:點擊
就是修改/etc/pam.d/sshd,把下面這行注釋:
session required pam_loginuid.so
不過,我在系統中並沒有找到這行。反而,從日誌可以看到,報錯是由PAM調用remote發出的,所以,我修改/etc/pam.d/remote,把這行注釋:
引用
session required pam_loginuid.so
這樣,確認不會再報上面的錯誤。但登陸的時候,日誌就會顯示:
Nov 19 10:06:31 printserver sshd[9582]: Accepted publickey for root from 192.168.228.244
port 1228 ssh2
Nov 19 10:06:31 printserver remote(pam_unix)[9584]: session opened for user root by (uid=0)
Nov 19 10:06:31 login -- root[9584]: ROOT LOGIN ON pts/2 FROM 192.168.228.244
發出資訊的主機從printserver改為login了,日誌分類會有有錯,不利於使用咯。
◎至於因為核心沒有開啟CONFIG_AUDIT功能引起的解決辦法
經確認,紅旗DC Server 5.0的核心是已經開啟CONFIG_AUDIT的,所以,解決方案無效。