~alpine/users

1

Setting up SSH server inside docker

Valentin Tunev <vlttnv@fastmail.com>
Details
Message ID
<CC3BFA01-F642-45BA-ACD2-17131289903F@fastmail.com>
DKIM signature
missing
Download raw message
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
Details
Message ID
<C3AD3099-217B-4529-BA7A-066FA9E486C3@goodeast.com>
In-Reply-To
<CC3BFA01-F642-45BA-ACD2-17131289903F@fastmail.com> (view parent)
DKIM signature
missing
Download raw message
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 <vlttnv@fastmail.com> wrote:
> 
> 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
Reply to thread Export thread (mbox)