登录后显示 SSH 消息,然后限制用户使用账户

登录后显示 SSH 消息,然后限制用户使用账户

我想“阻止/限制”我的专用服务器上的某个帐户,但我希望允许用户登录,然后我希望为他弹出消息(例如在 putty 中),然后关闭连接(这样 putty 窗口就会打开,他可以读取它,但他不能在控制台中执行/输入任何操作)。

我记得以前我在 freebsd 上做过类似的事情,但是找不到任何关于如何解决这个问题的有用信息。

有什么帮助吗?

答案1

1.编辑/etc/ssh/sshd_config并在底部添加这些指令:

Match User guest
    Banner /etc/ssh/banner_guest
    DenyUsers guest
Match all
  • 用实际的用户名更改guest

2.创建横幅文件:sudo nano /etc/ssh/banner_guest,并在其中输入您的消息,例如:

+------------------+
| Get out of here! |
+------------------+

3.重新启动 SSH 服务器:

sudo systemctl restart ssh.service

结果是:

在此处输入图片描述

在此处输入图片描述

编辑:

请注意,无论上述示例中PubkeyAuthentication是否可用,并且存在有效文件,用户都会获得/home/guest/.ssh/authorized_keysPermission denied (publickey).

如果PasswordAuthentication可用,系统会多次询问用户密码,最后会得到Permission denied (password).所以如果您想进一步戏弄他(或她),请按以下方式更改上述指令:

Match User guest
    PasswordAuthentication yes
    PubkeyAuthentication no
    MaxAuthTries 20
    Banner /etc/ssh/banner_guest
    DenyUsers guest
Match all

对我来说,最干净的方式就是显示消息并踢出他们:

Match User guest
    PasswordAuthentication no
    PubkeyAuthentication no
    MaxAuthTries 1
    Banner /etc/ssh/banner_guest
    DenyUsers guest
Match all

上述结果与第一个建议的结果相同,但不会出现消息Permission denied (publickey)( )。Server refused our key

答案2

我猜你指的是/usr/sbin/nologin壳。

这比其他答案实现这种更复杂的方法要简单得多。只需添加:

Match User guest
  ForceCommand /usr/sbin/nologin

用户将收到以下消息:

This account is currently not available.

(或其他配置/etc/nologin.txt

相关内容