3

I log into git-shell with PuTTy using a password. Whatever I type into the git-shell (the restricted login shell on a Debian linux server) results in a response like "unrecognized command".

git> git help -a
unrecognized command 'git'
Rusty
  • 33
  • 1
  • 5
  • 1
    `git-shell` is not a general purpose shell. It can only run certain commands non-interactively by default. To use it interactively, you have to do more, including define the actual commands you can use. You should read the [man page](https://git-scm.com/docs/git-shell). – Dan Lowe Jan 09 '17 at 15:19
  • Are you sure? The manual says: "... plus custom commands present in a subdirectory named git-shell-commands". Well, that subdir exists, but I just want to use standard commands, thus it is empty. I would be happy for _any_ standard command that works, for a start. – Rusty Jan 09 '17 at 17:32

1 Answers1

5

git-shell is, by design, very limited. See the man page for more details.

By default, it can only run a few commands, to allow for push/pull actions. This is a way for git servers to offer "safe" SSH access that is limited to only interacting with git repositories. Also by default, there is no interactive login access.

Note that simply to do push/pull/fetch operations using git-shell, you do not need to do anything special. It can already do those things. You only need to define custom commands if you want to do something unusual.

You say in comments that you have a ~/git-shell-commands/ directory, but it is empty. The presence of the directory will enable interactive mode, so you are getting a git> prompt. However, that the commands directory is empty means there are no valid commands you can run. In this scenario, the only thing you can run is exit to leave the shell.

To use git-shell, you will need to create some commands in ~/git-shell-commands. What exactly to create is up to you. An example might be to create list, and have that script return a list of the available repositories on the server.

If you want to use "standard commands," as you indicate in the comments, then I think the answer is that git-shell is not the tool you are looking for. It sounds like you are looking for a regular login shell.

An example custom command might look like this. Here's an implementation of the list command I suggested above.

#!/bin/bash

# Assuming all repositories are named `*.git`
for repo in $(ls -d *.git); do

    # Just in case one exists, ignore ".git"
    if [[ "$repo" != ".git" ]];
        # Trim off the extension
        echo $(basename $repo .git)
    fi

done

There are a couple of examples in this blog post.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • > By default, it can only run a few commands, to allow for push/pull actions. – Rusty Jan 10 '17 at 10:04
  • 1
    And that is all I want. Could you perhaps give an example for such a command? Unfortunately, I did not find one on the web. – Rusty Jan 10 '17 at 10:13
  • 1
    @Rusty They're just shell scripts. I added a pretty basic example of a list command to my answer. – Dan Lowe Jan 10 '17 at 15:27
  • @Rusty If you're saying you just want to use this for push/pull, it can already do that. Just set the user's shell to `git-shell` and point your git client to it, it already knows how to use e.g. git-receive-pack and so on to do what it needs. But you were asking about the interactive shell, which is different. – Dan Lowe Jan 10 '17 at 15:30
  • Thank you! This was the crucial point: **To connect to the git-shell with a git client, not logging in manually.** It knows what to do, indeed, and so the default use cases do work just like with any other login shell. (My empty `~/git-shell-commands` directory still existing.) – Rusty Jan 11 '17 at 10:49
  • @Rusty Cool, glad it is working out for you. I updated my answer a bit to emphasize this part so it is more clear. – Dan Lowe Jan 11 '17 at 14:08