某年更新:如果没有必要我认为还是不要关闭PAM选项。
根据网上教程,在修改允许私钥登录后,我修改了/etc/ssh/ssh_config
中的PasswordAuthentication
项,改为no
,重启sshd服务后发现依然能使用密码登录。
查资料得知,由于我的UsePAM
项为yes
,系统的安全认证由PAM模块接管,我看网上都是直接关掉PAM的,但是我感觉这样不是很安全(虽然确实没必要)。总之继续干了。
根据配置文件里的信息
# It is recommended to use pam_motd in /etc/pam.d/sshd instead of PrintMotd,
# as it is more configurable and versatile than the built-in version.
我找到了PAM关于ssh的配置文件/etc/pam.d/sshd
,查到有行为auth substack password-auth
,猜测是密码鉴权,我把这行注释掉并保存,发现已经无法通过密码进行ssh连接。
注意,我不知道这么做会不会产生其他影响。看来redhat系的linux安全性就是高。
不把PasswordAuthentication
改为no
的话似乎会允许你进行第一次登录尝试,但是密码登录最终会被拒绝掉,改为no
就直接拒绝了