Answers:
不。它不是“允许”命令,而是“强制”命令(作为ForceCommand选项)。
唯一的可能性是对不同的命令使用不同的键或从中读取参数stdin。
每个键只能有一个命令,因为该命令是“强制的”。
但是您可以使用包装器脚本。被调用的命令将原始命令行作为环境变量获取$SSH_ORIGINAL_COMMAND,可以对其进行评估。
例如~/.ssh/allowed-commands.sh:
#!/bin/sh
#
# You can have only one forced command in ~/.ssh/authorized_keys. Use this
# wrapper to allow several commands.
case "$SSH_ORIGINAL_COMMAND" in
    "systemctl restart cups")
        systemctl restart cups
        ;;
    "shutdown -r now")
        shutdown -r now
        ;;
    *)
        echo "Access denied"
        exit 1
        ;;
esac
然后~/.ssh/authorized_keys用
command="/home/user/.ssh/allowed-commands.sh",…
在O'Reilly撰写的伟大的SSH《安全外壳:权威指南》一书的第八章中,有一个使用如下脚本的漂亮示例:
#!/bin/sh
/bin/echo "Welcome!
Your choices are:
1       See today's date
2       See who's logged in
3       See current processes
q       Quit"
/bin/echo "Your choice:"
read ans
while [ "$ans" != "q" ]
do
   case "$ans" in
      1)
         /bin/date
         ;;
      2)
         /usr/bin/who
         ;;
      3)
         /usr/bin/top
         ;;
      q)
         /bin/echo "Goodbye"
         exit 0
         ;;
      *)
         /bin/echo "Invalid choice '$ans': please try again"
         ;;
   esac
   /bin/echo "Your choice:"
   read ans
done
exit 0
在.authorized_keys文件中使用它的方式如下:
command="/path/to/your/script.sh" <ssh-key>
...这样做时会为您提供ssh:
Welcome!
Your choices are:
1       See today's date
2       See who's logged in
3       See current processes
q       Quit
Your choice:
scp,sftp还有一天其他所有可能有用的东西。
                    command一般选项无效吗?
                    其他方法使用例如给定用户的受限外壳或使用包装器,该包装器将命令限制在特定目录中找到的所有文件/脚本,从而允许在不更改包装器的情况下扩大命令列表。
另一篇文章介绍了一个通用脚本,该脚本还允许将命令行参数用作允许的命令,但允许使用以正则表达式表示的规则来锁定它们。
该示例将以以下方式表示:
command="only systemctl shutdown"
并.onlyrules使用以下内容制作文件:
\:^systemctl restart cups$:{p;q}
\:^shutdown -r now$:{p;q}
这种“仅”方法的优点在于,无需为每个用户和情况编写单独的脚本。
ForcedCommand
                    
SSH_ORIGINAL_COMMAND(perman sshd),以便在脚本中可用。还给出了允许某些模式SSH_ORIGINAL_COMMAND运行的自动脚本的示例。另请参见unixwars.blogspot.com/2014/12/getting-sshoriginalcommand.html