我需要允许用户运行一组有限的命令。
但不允许他们创build交互式会话。
就像GitHub一样。
如果你尝试没有命令ssh,它会问候你并closures会话。
我可以通过使用ForceCommand some-script来获得这个
但是,进入some-script我需要评估用户的input。
也许在sshd_config中的任何其他NoTTY的选项?
—更新—
我正在寻找一个纯粹的SSH / Bash解决scheme,而不是Perl / Python /等。 黑客。
您正在将ForceCommand设置为脚本。 您需要检查SSH_ORIGINAL_COMMAND环境variables,其中包含用户提供给SSH客户端的实际命令。 例如:
#!/bin/sh case "$SSH_ORIGINAL_COMMAND" in date) date ;; fortune) fortune ;; *) echo "Valid commands are: date, fortune" exit 1 ;; esac
用户可以执行如下命令:
% ssh localhost fortune Q: How much does it cost to ride the Unibus? A: 2 bits.
如果用户没有提供命令,他们应该从脚本中得到错误信息(并且连接被终止):
% ssh localhost Valid commands are: date, fortune, rev Connection to localhost closed.
编辑:使用密钥authentication时,可以在authorized_keys中禁用terminal:
command="/usr/local/bin/restricted.sh",no-pty ssh-rsa AAA...
如果你只想允许git命令,用下面的命令将用户的shell设置为git-shell :
usermod -s /usr/bin/git-shell <USERNAME>
git-shell是git包的一部分。
如果你想允许任意命令, mgorven的答案是要走的路。
看看AUTHORIZED_KEYS FILE FORMAT部分中的sshd手册页。 我想你正在寻找no-pty可选的选项。
看看这个脚本:
http://lists.fusionforge.org/pipermail/fusionforge-general/2012-May/001795.html
这是一个限制命令的Perl脚本…