Answers:
要学究一点,它不是ctrl + c,而是SIGHUP
(更接近ctrl + d)杀死了该应用程序。
您基本上可以将所需的任何内容放入用户的shell中/etc/passwd
。只需/bin/bash
用另一个程序替换用户passwd行上的默认值(可能是)即可。该程序可以是/usr/bin/tail_log_file
具有以下内容的脚本,例如,由root:root拥有,具有umode 0755:
#!/bin/rbash
tail -f /path/to/logfile
您可以使用rbash以外的其他解释器,但是在这种情况下,建议使用受限制的shell。
要对其进行极其繁琐的操作,您应该将脚本的路径添加到/etc/shells
,但是我通常发现它仍然可以正常工作。
还请记住,用户可能会将脚本放在后台,或者使用某些选项(ssh username@host bash
)仍然获得外壳。如果要以这种方式限制用户,则只有真正的文件系统权限才是真正的解决方案。
/etc/shells
是允许拥有其他内容作为其shell的用户将shell设置为此。超级用户(root
)始终可以将任何人的shell更改为他们想要的任何东西。
/etc/shells
因为这将允许用户更改其shell(因为这/usr/bin/tail_log_file
将被视为“不受限制的shell”)!
您可以将ssh配置为在使用公共密钥身份验证登录时运行您选择的命令。为此,生成一对密钥:
djs@sardinia:~$ ssh-keygen -f restricted-key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in restricted-key.
Your public key has been saved in restricted-key.pub.
The key fingerprint is: b1:8f:26:47:c2:c5:f2:8d:ed:a0:c4:bd:9a:30:9d:08 djs@sardinia
[...]
restricted-key.pub
包含适合放入用户~/.ssh/authorized_keys
文件的行:
ssh-rsa AAAA...UDz47Nl djs@sardinia
但是您可以向其中添加命令,并且使用密钥登录时,ssh将运行该命令:
command="tail -f /my/interesting/file" ssh-rsa AAAA...UDz47Nl djs@sardinia
然后,用户可以使用SSH到机器ssh -i restricted-key
。