我试图禁用root密码login,只允许在debian 7上用ssh密钥进行rootlogin。
cat << EOF >> /etc/ssh/sshd_config PasswordAuthentication yes UsePAM no PermitRootLogin without-password AllowUsers root test Port 433 LoginGraceTime 1m ClientAliveInterval 600 ClientAliveCountMax 0 EOF service ssh restart
我将这些命令作为部署脚本的一部分运行,但是仍然可以使用根密码(而不是使用ssh密钥)以root用户身份login。
我已经阅读了很多教程,我似乎无法明白为什么会发生这种情况。
你检查了“/ etc / ssh / sshd_config”的内容吗?
你的命令不重写这个文件,它附加到它。 此文件的第一行(默认)是“UsePAM yes”。
而这个选项将被使用,因为它来的更早…
如果你没有一个有效的ssh密钥,在这种情况下root会被要求input密码,因为你有'UsePAM yes'( http://www.techrepublic.com/blog/linux-and-open-source/specify -who-can-log-in-via-openssh / )。
PS您每次运行命令时都会将configuration行追加到文件中。 您需要直接编辑sshd_config,或者更改“部署脚本”来重写它,而不是附加到它。
您必须禁用PasswordAuthentication并启用PermitRootLogin
喜欢这个:
PasswordAuthentication no PermitRootLogin yes