3

I have just set up my own gitea service on the Ubuntu server (the server is run with user gitea). The following steps have been done:

  1. generate ssh key on my windows pc, and store at C:\Users<user_name>\.ssh, namely id_rsa_gitea and id_rsa_gitea.pub
  2. copy and set the public key on my gitea account setting page

There are existing key files for my GitHub account in the directory, namely id_rsa and id_rsa.pub. I modified the file config in the same directory as

Host github.com
  HostName github.com
  User git
  IdentityFile C:/Users/<user_name>/.ssh/id_rsa
  IdentitiesOnly yes
 
Host 192.168.200.101
  HostName 192.168.200.101
  User gitea
  IdentityFile C:/Users/<user_name>/.ssh/id_rsa_gitea
  IdentitiesOnly yes

Pushing to GitHub works fine. But when I try to push to gitea, it gets

$ git push -u origin master
gitea@192.168.200.101's password:
Permission denied, please try again.
gitea@192.168.200.101's password:
Permission denied, please try again.
gitea@192.168.200.101's password:
\302\226gitea@192.168.200.101: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have tested the ssh connection in the git bash console with ssh -v gitea@192.168.200.101, and gets

OpenSSH_7.6p1, OpenSSL 1.0.2m  2 Nov 2017
debug1: Reading configuration data /c/Users/admin/.ssh/config
debug1: /c/Users/admin/.ssh/config line 26: Applying options for 192.168.200.101
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.200.101 [192.168.200.101] port 22.
debug1: Connection established.
debug1: identity file C:/Users/admin/.ssh/id_rsa_gitea type 0
debug1: key_load_public: No such file or directory
debug1: identity file C:/Users/admin/.ssh/id_rsa_gitea-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.200.101:22 as 'gitea'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:YqpRDueradBcei52m4ahex5DgTOwI3QvgJohoZSMzTs
debug1: Host '192.168.200.101' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/admin/.ssh/known_hosts:23
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:DCCnO6UzUiXYhZiNxeaS4SV05fIUZhHK/ZGDPPI6cwc C:/Users/admin/.ssh/id_rsa_gitea
debug1: Server accepts key: pkalg rsa-sha2-512 blen 535
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.200.101 ([192.168.200.101]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: PTY allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: PTY allocation disabled.
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to 192.168.200.101 closed.
Transferred: sent 3720, received 3624 bytes, in 0.2 seconds
Bytes per second: sent 15126.0, received 14735.7
debug1: Exit status 1

I've tried multiple variations of this, but none of them seem to work. Any ideas?

Update: Push with http works fine. I switched back to ssh and tried to push again, now I get:

Pushing to gitea@192.168.200.101:guanhuizhe/example-repo.git
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

During this push the sshd log of the ubuntu server is:

Oct 16 18:08:29 DataStorage2 sshd[29981]: Accepted publickey for gitea from 192.168.200.141 port 14967 ssh2: RSA SHA256:DCCnO6UzUiXYhZiNxeaS4SV05fIUZhHK/ZGDPPI6cwc
Oct 16 18:08:29 DataStorage2 sshd[29981]: pam_unix(sshd:session): session opened for user gitea by (uid=0)
Oct 16 18:08:29 DataStorage2 sshd[30017]: Received disconnect from 192.168.200.141 port 14967:11: disconnected by user
Oct 16 18:08:29 DataStorage2 sshd[30017]: Disconnected from 192.168.200.141 port 14967
Oct 16 18:08:29 DataStorage2 sshd[29981]: pam_unix(sshd:session): session closed for user gitea

Update v2:

The problem is caused by the Ubuntu user I used to run the gitea binary. This user does not have shell. I delete the user and configure a normal user. Everything works fine. Thanks for every one!!

AThaBlen
  • 51
  • 1
  • 5
  • A better test would be `ssh -v 192.168.200.101` because it will also check that the user in `~/.ssh/config` is correct. – Thomas Oct 16 '20 at 10:17
  • @Thomas I run `ssh -v 192.168.200.101` and it looks the same as `ssh -v gitea@192.168.200.101` so I guess the username is right. – AThaBlen Oct 16 '20 at 10:34
  • @AThaBlen Did you try and change the remote as I mention in my answer? – VonC Oct 16 '20 at 10:36
  • @VonC I have tried and it promps ` fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.` – AThaBlen Oct 16 '20 at 10:38
  • @AThaBlen Do you see a `Hi there, xxx! You've successfully authenticated with the key named yyy` when you do a `ssh -Tv gitea` (assuming you have renamed the Hoist entry as suggested in the answer)? – VonC Oct 16 '20 at 10:42
  • @VonC No ... But when I tried `ssh -Tv git@github.com` I can see this. – AThaBlen Oct 16 '20 at 10:47
  • @AThaBlen As long as you don't see this, the gitea authentication does not work. That is the first issue to fix. – VonC Oct 16 '20 at 10:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/223148/discussion-between-vonc-and-athablen). – VonC Oct 16 '20 at 10:50

1 Answers1

0

\302\226gitea@192.168.200.101 means the origin in the local git config file .git/config is not gitea, but <START OF GUARDED AREA>gitea.

You can change your Host entry (in ~/.ssh/config) with "gitea" (easier to type than 192.168.200.101)

Test it with:

ssh -Tv gitea

Check also the ~gitea/.ssh/authorized_keys file, to ensure the public key has been added by gitea, and is in a SSH forced command line.
You should see something like:

command="/path/to/gitea --config='/path/to/app.ini' serv key-2",\
   no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty \
   ssh-rsa <yourPublicKey>

If you want to use your ~/.ssh/config entry, then you will need to change your remote:

cd /path/to/repo
git remote set-url origin gitea:<me>/myrepo
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your reply! I check the spaces in my config file and the authorized_keys file, it looks like: command="/home/gitea/gitea --config=\"/home/gitea/custom/conf/app.ini\" serv key-4",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty It still cannot work QAQ. I've updated the questions. – AThaBlen Oct 16 '20 at 10:21
  • @AThaBlen your remote is wrong: I have edited my answer. – VonC Oct 16 '20 at 10:22