1

I am attempting to setup a private git server on my local network and I cannot for the life of me figure out what I am doing wrong. I can't seem to get ssh authentication via private key working for the git user.

I have run ssh-keygen on the client to create an rsa pub/private key. I have created the ~/.ssh/authorized_keys file on the server. I have copied the contents of id_rsa.pub over to the authorized_keys file on the server, by using scp to transfer the file to the server and then cat id_rsa.pub > ~/.ssh/authorized_keys on the server to ensure there were no copy errors. I have restarted the ssh daemon.

On the client, the ~/.ssh folder has permissions 700, and the ~/.ssh/id_rsa file has permissions 600. On the server, the ~/.ssh folder has permissions 700, and the ~/.ssh/authorized_keys file has permissions 600.

My server's ssh config at /etc/ssh/sshd_config has the following uncommented lines

Include /etc/ssh/sshd_config.d/*.conf
KbdInteractiveAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp  /usr/lib/openssh/sftp-server
PasswordAuthentication yes
Match User git
        PasswordAuthentication no
        PubkeyAuthentication yes

The /etc/ssh/sshd_config.d/ folder is empty. The server is running Ubuntu 22.04.1 LTS. The server's ssh version is OpenSSH_8.9p1 Ubuntu-3ubuntu0.1, OpenSSL 3.0.2 15 Mar 2022

Upon attempting to ssh [email protected] I am greeted with the following
Permission denied (publickey).

What am I missing? I've looked at guides. I've made sure I am copying the key over accurately. I am honestly stumped because I have inserted public keys into the authorized_keys file before on a server with ssh already setup, and it's worked. If I set the sshd config to allow PasswordAuthentication then I can login as the git user fine with the password I have set on it. I do not understand why the public private key auth is not working.

Output of ssh [email protected] -vvv
https://pastebin.com/raw/nJwskYhU

1
  • 1
    According to the pastebin, your client is offering id_rsa to the server, and the server isn't accepting it. Try checking the syslogs on the server to see if the sshd process is logging the reason why it's not accepting the key. Otherwise, please run "ls -la .ssh" on the server and edit your question to add the output.
    – Kenster
    Commented Feb 20, 2023 at 21:02

1 Answer 1

1

There was an error in /var/log/auth.log which stated:
Authentication refused: bad ownership or modes for directory <home directory>

What I had done is moved the git user's home directory to a new location, and this folder had different than standard permissions and ownership than home directories do by default. I assume this was the problem. Moving the home directory back to what it was fixed the issue. Thank you to Kenster for their comment. I did not think to look for logs on the server side.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.