Subject: Setting up SSH server inside docker

From: Valentin Tunev <[email-masked]>
Date: Thu, 7 Sep 2023 17:51:37 +0300

Hello everyone,

I have stumbled across an odd issue when trying to set up an SSH server using Alpine as a base for a docker image.
I am getting a "git@localhost: Permission denied (publickey).” error, although the correct key is inside athorized_keys. I have also set the correct permissions for the directories.

After a lot of debugging if found out that I recreate the set up (install git, openssh, create bare repo) for the root user I am able to clone, ssh into the server etc. But as soon as I create a new user “git” and set up a bare repository and authorized_keys I start getting the permissions error.

The logs from the ssh server don’t show anything interesting, just that the public key is being rejected. Logs on the client side show the same.

Here’s my Dockerfile: https://pastebin.com/jPLqJfQc

I would appreciate any pointers because I am not sure what to debug any more.

Thanks,
Val

---

From: Paul Suh <[email-masked]>
Date: Wed, 20 Sep 2023 04:12:29 +0000

Maybe you’ve been able to get this to run, but I finally got a few minutes and took a look. 

You have two or three things that you need to fix: 

1. You need to unlock the git user. When the user account is created it is locked by default. To do this, run:

    passwd -d git

2. To get an interactive shell you need to create the directory /home/git/git-shell-commands. The expected use case is in general non-interactive, so you shouldn’t need to do this, but I’ve created it as an example. I also cleaned up and tightened the block that creates the git user’s home dir. For more info see https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

3. Remove the -d flag from the sshd entry point. Otherwise, the daemon will exit and the container will halt after a single ssh connection. 

Updated Dockerfile: https://pastebin.com/2JMKd9TB

Hope this helps. 

—Paul

> On Sep 7, 2023, at 10:51 AM, Valentin Tunev <[email-masked]> wrote:
> 
> Hello everyone,
>