gpt4 book ai didi

bash - 使用ssh推送到gitea时询问密码

转载 作者:行者123 更新时间:2023-12-05 06:59:33 24 4
gpt4 key购买 nike

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

  1. 在我的 windows 电脑上生成 ssh key ,并存储在 C:\Users \.ssh,即 id_rsa_giteaid_rsa_gitea.pub
  2. 在我的gitea账户设置页面复制并设置公钥

该目录下已有我的GitHub账号的 key 文件,即id_rsaid_rsa.pub。我在与

相同的目录中修改了文件 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
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.

我已经在 git bash 控制台中使用 ssh -v gitea@192.168.200.101 测试了 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: 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

我已经尝试了多种变体,但似乎都不起作用。有什么想法吗?

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

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.

在本次推送过程中,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\226gitea@192.168.200.101表示 origin在本地 git 配置文件中 .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条目,那么您将需要更改您的 Remote :

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

关于bash - 使用ssh推送到gitea时询问密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64386716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com