Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用gitshell的自定义命令_Linux_Git_Shell_Ssh - Fatal编程技术网

Linux 使用gitshell的自定义命令

Linux 使用gitshell的自定义命令,linux,git,shell,ssh,Linux,Git,Shell,Ssh,如何为git shell创建自定义命令?根据报告: 当给定-c时,程序以非交互方式执行; 可以是git接收包、git上传包、git 上载存档文件、cvs服务器或命令目录中的命令。贝壳是 在没有参数的情况下以交互模式启动;在这种情况下,, 命令_DIR必须存在,并且其中的任何可执行文件都可以是 调用 然而,我不确定我是否正确理解了这一点。我创建了一个名为gituser的用户,并将/usr/bin/gitshell作为shell提供给他。我创建了一个名为gitshellcommands的目录,并在其

如何为git shell创建自定义命令?根据报告:

当给定-c时,程序以非交互方式执行; 可以是git接收包、git上传包、git 上载存档文件、cvs服务器或命令目录中的命令。贝壳是 在没有参数的情况下以交互模式启动;在这种情况下,, 命令_DIR必须存在,并且其中的任何可执行文件都可以是 调用

然而,我不确定我是否正确理解了这一点。我创建了一个名为gituser的用户,并将/usr/bin/gitshell作为shell提供给他。我创建了一个名为gitshellcommands的目录,并在其中放入了一个名为“testy”的脚本,但我无法使它通过gitshell运行

以下是我在另一台机器上尝试的内容:

$ ssh gituser@server.com testy
fatal: unrecognized command 'testy'
注意gitshell正在工作,并且正在响应,它只是找不到我的自定义命令

下面是脚本:

:/home/gituser/git-shell-commands# ls -l -a
total 12
drwxr-xr-x 2 gituser gituser 4096 Jan 22 17:35 .
drwxr-xr-x 4 gituser gituser 4096 Jan 22 13:57 ..
-rwxr-xr-x 1 gituser gituser   26 Jan 22 13:58 testy
:/home/gituser/git-shell-commands# ./testy
hello!
:/home/sodigit/git-shell-commands# cat testy
echo "hello!"

我做错了什么?如何使用git shell运行自定义命令?

事实证明,git 1.7.4中引入了此功能。我使用的是debian Squence,它包含了git的一个旧版本,所以这就是它不起作用的原因

如果遇到此问题,请检查git版本


但是,从Git1.7.10开始,自定义命令只在交互模式下工作,而不与-c一起工作。我还没有尝试过最新的git,所以这个问题可能与软件版本无关。

要允许1.7.4之前版本(以及1.7.10的非交互式模式)使用自定义命令,可以使用git shell的shell脚本包装器:

#!/bin/bash                                                                     

cmdline=($1)
cmd=$(basename "${cmdline[0]}")

if [ -z "$cmd" ] ; then
    exec git-shell
elif [ -n "$cmd" -a -x ~/git-shell-commands/"$cmd" ] ; then
    ~/git-shell-commands/"$cmd" "${cmdline[@]:1}"
else
    exec git-shell -c "$1"
fi
在通常使用“gitshell”的地方,请参考此脚本,但不要使用此脚本的任何“-c”参数

与git shell一样,上面的脚本要求将整个命令行作为第一个参数传递。如果希望将命令行作为单独的参数传递:

#!/bin/bash                                                                     

cmd=$(basename $1)

if [ -z "$cmd" ] ; then
    exec git-shell
elif [ -n "$cmd" -a -x ~/git-shell-commands/"$cmd" ] ; then
    shift
    ~/git-shell-commands/"$cmd" "$@"
else
    exec git-shell -c "$*"
fi
例如,这允许您在authorize_密钥中调用受限shell,如下所示:

command="sshsh $SSH_ORIGINAL_COMMAND" ...
请注意,这两个脚本都没有为1.7.4之前的版本创建交互模式(尝试启动交互会话将导致git shell出现“致命:你认为我是什么?shell?”错误),但不应干扰1.7.4及更新版本中的交互模式


免责声明:未对安全漏洞进行审查。使用风险自负。特别是,~/git shell命令中的每个命令都是一个潜在的安全漏洞(尽管git shell 1.7.4和更高版本也是如此,即使没有上述任何脚本)。

您是如何启动git shell的?您是否定义了
命令\u DIR
?我没有定义它。我假设它是$HOME/git shell命令,其中$HOME是gituser的主目录(/HOME/gituser)。我使用ssh访问git shell,如上面的示例所示。文档清楚地说明脚本需要放在
COMMAND\u DIR
中。如果您不知道它指向哪个目录,那么如何将文件放在其中?文档中还声明“COMMAND_DIR是路径“$HOME/git shell commands”。“我假设$HOME是用户的主目录。然而,我可能错了。如何检查这个命令_DIR在哪里?+1刚刚出现了完全相同的问题,您为我节省了几天的调试时间,谢谢。