我有一台小型服务器,我希望能够使用 SSH 通过两种方法登录:
- 公钥
- 密码进而用 Python 制作的 PAM
我成功安装libpam-python
,并将此行添加到/etc/pam.d/sshd
:
auth requisite /lib/x86_64-linux-gnu/security/pam_python.so /lib/x86_64-linux-gnu/security/my_pam.py
为了举例子,我们假设我的 python pam 可以工作,并且只要求输入另一个密码。
以下是我的相关参数/etc/ssh/sshd_config
:
# PAM
UsePAM yes
ChallengeResponseAuthentication yes
# Regular password
PasswordAuthentication yes
PermitEmptyPasswords no
# Authentication Methods
# Either an authorised public key, or the password + another one (python pam).
AuthenticationMethods publickey password,keyboard-interactive:pam
不幸的是,这不起作用:
# I am not using an authorized public key
me@client:~$ ssh user@myserver
user@myserver's password:
Permission denied, please try again.
user@myserver's password:
Permission denied, please try again.
user@myserver's password:
Permission denied (publickey,password).
我的密码正确!如果我将参数改回默认值,我的密码就会被识别,我就可以登录了!
问题似乎出在AuthenticationMethods
参数上。如果我删除它,它就可以正常工作:
me@client:~$ ssh user@myserver
Python PAM password:
Password OK!
END OF PYTHON PAM.
Password:
user@myserver:~$
请注意,经典user@myserver's password:
已被严厉取代Password:
。
不幸的是,即使它有效,我也无法选择这两种方法的顺序(我想要相反的顺序),而且经典的密码方法似乎已被 PAM 版本取代,我不知道,因此有点困扰我。
我该如何解决这个问题?