阻止所有用户通过SSH访问

我目前可以通过ssh以root身份login到我的服务器。 可能有一些其他用户,但是,有ssh访问。 我想阻止任何可能的login,除了从根。 我怎样才能做到这一点?

谢谢。

所以你可以用你的sshd_config文件中的AllowUsers指令实现你所说的愿望,例如:

$ grep AllowUsers /etc/ssh/sshd_config AllowUsers root 

但是我会对使用ssh的root账号保持警惕 – 考虑一下正常使用的非特权账号,只有在需要的时候使用类似sudo才能获得root权限。

从man sshd_config

  AllowUsers This keyword can be followed by a list of user name patterns, separated by spaces. If specified, login is allowed only for user names that match one of the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pat‐ tern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups. See PATTERNS in ssh_config(5) for more information on patterns. 

顺便说一句。 请不要让root用户的密码login。 只允许SSH密钥,甚至更好的只是让一个特定的用户login,并改变到根,而不是直接根。