禁用SSH交互式login

我想有条件地禁用ubuntu中的交互式login,如果用户试图用无效的用户名login到ssh shell。

说我有我的服务器上的用户'bob',但用户'fred; 不是有效的用户。

当鲍勃login

ssh bob@my_ip_address 

我想要一个交互式login

当有人login

 ssh fred@my_ip_address 

我不希望任何交互式login和login尝试终止。

在Ubuntu中如何做到这一点?

你真的不想这样做。 OTOH, fail2ban只是正是你想要的。 您可以将其设置为检测并禁止在一段时间内尝试以无效用户身份login的IP。

joet3ch也是正确的说切换到公共密钥login只会是最安全的。

你是否意识到这一点很容易find一个有效的用户名? 您总是希望攻击者尽可能less地了解您的系统!
作为fail2ban的替代scheme,你也可以使用denyhosts看起来和fail2ban完全一样。

/etc/ssh/sshd_config ,可以使用AllowUsers参数指定允许哪些用户通过SSHlogin:

 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 pattern 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. 

另外,我真的build议使用SSH密钥而不是密码来保护连接。