以只有 git-shell 的用户上传文件

问题描述 投票:0回答:1

我的服务器上有一个用户在

/usr/bin/git-shell
中有
/etc/passwd

如何将文件上传到服务器上我拥有所有者权限的文件夹

~/www/

如果我尝试 scp,我会收到此错误:

$ scp index.html [email protected]:~/www/
fatal: unrecognized command 'scp -t ~/www/'
lost connection
bash git scp git-shell
1个回答
0
投票

scp 与 git-shell

可以通过以下方式允许将

scp
git-shell
一起使用 在远程用户主目录的
scp
中创建以下
git-shell-commands
可执行文件:

#!/bin/sh

exec /usr/bin/scp "$@"

例如,它是在 frugalware git-hooks repo 中完成的。

还可以自定义该文件,以允许仅在某些条件下使用

scp
,例如,对于特定的公钥。

详情

它之所以有效,是因为本地

scp
调用使用
scp
-t
参数执行远程
-f
ssh 命令。该协议在这里进行了解释https://stackoverflow.com/a/50644600/4023446

使用

git-shell
时,仅允许目录
git-shell-commands
中的命令。因此,上述脚本在远程 scp 会话期间执行,启动实际的
/usr/bin/scp
二进制文件。

© www.soinside.com 2019 - 2024. All rights reserved.