使用SSH推送到gitea时询问密码

问题描述

我刚刚在ubuntu服务器上设置了自己的gitea服务(该服务器由用户gitea运行)。已完成以下步骤:

  1. 在我的Windows pc上生成ssh密钥,并存储在C:\ Users \。ssh中,即id_rsa_giteaid_rsa_gitea.pub
  2. 在我的gitea帐户设置页面上复制并设置公共密钥

目录中存在我的GitHub帐户的现有密钥文件,即id_rsaid_rsa.pub。我在与{p>相同的目录中修改文件config

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

推送到GitHub可以正常工作。但是当我尝试使用gitea时,它会得到

$ git push -u origin master
[email protected]'s password:
Permission denied,please try again.
[email protected]'s password:
Permission denied,please try again.
[email protected]'s password:
\302\[email protected]: Permission denied (publickey,password).
fatal: Could not read from remote repository.

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

我已经用ssh -v [email protected]在git bash控制台中测试了ssh连接,并获得了

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: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] 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 [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] 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 [email protected] 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

我已经尝试了多种变体,但是似乎都没有。有什么想法吗?

更新:使用http推送可以正常工作。我切换回ssh并尝试再次推送,现在我得到了:

Pushing to [email protected]:guanhuizhe/example-repo.git
fatal: Could not read from remote repository.

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

在此推送期间,ubuntu服务器的sshd日志为:

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

更新v2:

问题是由我用来运行gitea二进制文件的Ubuntu用户引起的。该用户没有外壳。我删除用户并配置一个普通用户。一切正常。谢谢大家!

解决方法

\302\[email protected]表示本地git配置文件origin中的.git/config不是gitea,而是<START OF GUARDED AREA>gitea

您可以使用“ Host”(比键入~/.ssh/config更容易键入)来更改gitea项(在192.168.200.101中)

使用以下方法进行测试:

ssh -Tv gitea

还要检查~gitea/.ssh/authorized_keys文件,以确保公用密钥已由gitea添加,并且在SSH强制命令行中。
您应该看到类似以下内容的

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>

如果要使用~/.ssh/config条目,则需要更改遥控器:

cd /path/to/repo
git remote set-url origin gitea:<me>/myrepo