Ubuntu 16 Sudo SU 密碼嘗試不正確

Ubuntu 16 Sudo SU 密碼嘗試不正確

我正在使用 Ubuntu 16.04.3 LTS 伺服器。我有一個具有 sudo 權限的使用者。當我嘗試從目前使用者切換到 root 使用者時,它會要求我輸入密碼。我輸入了正確的密碼,但它拒絕我的密碼。

username@server:/ sudo su
[sudo] password for username:
Sorry, try again.
[sudo] password for username:
Sorry, try again.
[sudo] password for username:
sudo: 3 incorrect password attempts

幸運的是,我打開了另一個終端機窗口,我仍然以 root 身份登入。所以我嘗試為我的用戶重置密碼。它說我已成功更新用戶。

root@server:/# passwd username
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

所以我然後再次嘗試該sudo su命令。它失敗並顯示相同的訊息。

我為同一用戶打開一個新的終端機視窗並嘗試,sudo su但相同的命令失敗並顯示相同的訊息。

我也嘗試解鎖用戶sudo usermod --expiredate -1 username。這也沒有解決問題。

我還嘗試授予用戶“sudo”權限usermod -aG sudo username。用戶仍然遇到這個問題。

我放棄了,只是創建了一個具有 sudo 權限的新用戶並開始使用新用戶。第二天,我開始與新用戶遇到完全相同的問題。

pwck命令列出了幾個系統帳戶和有關其主目錄的訊息,但沒有列出其他內容。該grpck命令根本沒有給出任何訊息。

大約一個月前,我們最近新增了「pam」身份驗證。

/etc/pam.d/sudo

#%PAM-1.0

session    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
@include common-account
@include common-session-noninteractive

/etc/pam.d/common-auth

auth    required        pam_tally2.so deny=5 unlock_time=600
# here are the per-package modules (the "Primary" block)
auth    [success=1 default=ignore]      pam_unix.so nullok_secure
# here's the fallback if no module succeeds
auth    requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
auth    required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
auth    optional                        pam_cap.so
# end of pam-auth-update config

/etc/pam.d/common-account

# here are the per-package modules (the "Primary" block)
account [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so
# here's the fallback if no module succeeds
account requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
account required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config

/etc/pam.d/common-session-noninteractive

# here are the per-package modules (the "Primary" block)
session [default=1]                     pam_permit.so
# here's the fallback if no module succeeds
session requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
session required                        pam_permit.so
# The pam_umask module will set the umask according to the system default in
# /etc/login.defs and user settings, solving the problem of different
# umask settings with different shells, display managers, remote sessions etc.
# See "man pam_umask".
session optional                        pam_umask.so
# and here are more per-package modules (the "Additional" block)
session required        pam_unix.so
# end of pam-auth-update config

感謝@telcoM 和@roaima,我發現 pam 身份驗證模組是問題的原因。

root@server:/# pam_tally2
Login           Failures  Latest    failure     From
username           53    06/05/18   16:53:42    xxx.xxx.xxx.xxx

雖然我找到了問題的原因,但我不理解這種行為。也許我在 pam 模組中配置了不正確的東西。每次我輸入sudo su(成功與否)時,都會將失敗加到pam_tally2.我不知道為什麼成功輸入正確的密碼會增加失敗嘗試的次數,但事實確實如此。下面的例子。

pam_tally2
Login           Failures  Latest    failure     From
username           0    06/05/18   16:53:42    xxx.xxx.xxx.xxx

username@server:/ sudo su
[sudo] password for username:
root@server:/#

pam_tally2
Login           Failures  Latest    failure     From
username           1    06/05/18   16:54:03    xxx.xxx.xxx.xxx

使用sudo -ssudo -i也會導致增加 中的故障pam_tally2

答案1

您提到未經授權的外部使用者不斷嘗試登入。如果這些不需要的遠端登入嘗試引用root您的使用者帳戶,則username可能表示pam_tally2PAM 模組正在鎖定其中一個或兩個。

運行pam_tally2命令以查看導致失敗的原因。 (您可能需要運行pam_tally2 --user=username --reset以重置username.

或者,此問題報告如果 /etc/ssh/sshd_config 檔案中設定了“ChallengeResponseAuthentication yes”,pam_tally2 會將正確的密碼計為失敗的登入嘗試可以更準確地描述您的情況。 (我仍在努力尋找解決方案的替代來源。)


順便說一句,儘管 Canonical 做出了所有最好的(但錯誤的)努力,但您不應該需要將其用於sudo su任何用途。 (這就像說“給我根嗎?好的謝謝。現在我是root了,我需要成為root".) 嘗試sudo -s使用 root shell 或sudo -iroot 登入 shell。

相關內容