Upload files as a user that only has git-shell

267 Views Asked by At

I have a user on my server that has /usr/bin/git-shell in /etc/passwd.

How do I upload files to the folder ~/www/ on the server, where I have owner rights?

If I try scp, I get this error:

$ scp index.html [email protected]:~/www/
fatal: unrecognized command 'scp -t ~/www/'
lost connection
1

There are 1 best solutions below

0
Orest Hera On

scp with git-shell

It possible to allow usage of scp with git-shell by creating the following scp executable file in git-shell-commands in the remote user home directory:

#!/bin/sh

exec /usr/bin/scp "$@"

For example, it is done in the frugalware git-hooks repo.

The file can be also customized to allow usage of scp only for certain conditions, for example, for specific public keys.

Details

It works because a local scp call executes the remote scp ssh command with -t or -f argument. The protocol is explained here https://stackoverflow.com/a/50644600/4023446

When git-shell is used it allows only commands in the directory git-shell-commands. So, the above script is executed during remote scp sessions launching the actual /usr/bin/scp binary.