windows - 为什么gitea添加了ssh还需要密码登录?

标签 windows git ssh gitlab gitea

  1. 我安装了gitea(类似于gitlab)
  2. 我在用户设置 -> SSH KEY中添加了有效的公钥
  3. gitea 端口 3000

运行:

ssh -p 22  -Tvv  git@***.***.***.***  

输出:

debug1: Found key in C:\\Users\\client/.ssh/known_hosts:17
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug2: key: C:\\Users\\client/.ssh/id_rsa (000001FBAD96F620)
debug2: key: C:\\Users\\client/.ssh/id_dsa (0000000000000000)
debug2: key: C:\\Users\\client/.ssh/id_ecdsa (0000000000000000)
debug2: key: C:\\Users\\client/.ssh/id_ed25519 (0000000000000000)
debug2: key: C:\\Users\\client/.ssh/id_xmss (0000000000000000)
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:W88rhRw****** C:\\Users\\client/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: C:\\Users\\client/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\client/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\client/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\client/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such file or directory
git@***.***.***.***'s password:

我真的不明白为什么?

在此之前,gitlab已安装,ssh工作正常,但后来gitlab被卸载,gitea被卸载已安装

我可以知道是什么原因吗?


在服务器中,运行:top

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                 
 1185 root      20   0  972600 158792  44828 S   0.0  7.7   0:06.96 gitea 

ssh git@***.***.***.***ssh root@***.***.** 之间有什么区别吗*.***

最佳答案

出现此问题的一个原因是 gitea 实例安装在主机上的 docker 容器中。当您使用 git 用户 shh 到主机时,您打算 ssh 进入 gitea docker 实例,但实际上您只是 ssh 进入运行 docker 的服务器。 SHH不使用域名,所以即使你有一个反向代理,它可以在服务器上看到你对gitea网站的请求,从gitea docker容器中获取gitea网站,并将其发送到你的计算机上,一个反向代理当您通过 ssh 登录到服务器时,无法执行相同的操作。

解决方案是设置某种形式的 SSH 容器直通。这记录在 gitea docker 安装文档页面 ( https://docs.gitea.io/en-us/install-with-docker/#ssh-container-passthrough ) 中。其 Gist 是:

  1. 在服务器上的 gitea 容器之外创建一个名为“git”的用户。
  2. 创建一个 key 对,并将其放入 git 用户的 ~/.ssh 文件夹中。
  3. 设置 gitea docker 卷以包含此 git 用户的 ~/.ssh 文件夹作为内部 docker 文件夹之一(即,与 gitea docker 容器的/data/共享包含 key 对的服务器的 git 用户的 ~/.ssh 文件夹) git/.ssh 文件夹
  4. 将 gitea 容器的 docker 用户设置为与服务器的 git 用户相同的用户 ID
  5. 需要将公钥添加到服务器的 git 用户的 ~/git/.ssh/authorized_keys 文件中(例如 sudo -u git cat /home/git/.ssh/id_rsa.pub | sudo -u git tee -a /home/git/.ssh/authorized_keys && sudo -u git chmod 600 /home/git/.ssh/authorized_keys )
  6. 在服务器上创建一个名为 gitea 的新命令,该命令是一个包含以下内容的文件:ssh -p 2222 -o StrictHostKeyChecking=no <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e09071a2e5f5c59405e405e405f" rel="noreferrer noopener nofollow">[email protected]</a> "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@" 。此文件应位于/usr/local/bin/gitea/中并且必须是可执行的 ( sudo chmod +x /usr/local/bin/gitea )
  7. 取下 docker 容器并将其备份(从 gi​​tea docker-compose.yml 文件所在的文件夹中, docker-compose down ,然后 docker-compose up -d )
  8. 在常规计算机上的命令提示符下进行测试:ssh -Tvv <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04636d70446c6b77706a6569612a676b69" rel="noreferrer noopener nofollow">[email protected]</a> 。如果它正常工作,您应该会看到一条消息“您好,!您已使用名为 [email protected] 的 key 成功进行了身份验证,但 Gitea 不提供 shell 访问。 如果这是意外情况,请使用密码登录并在另一个用户下设置 Gitea。”您还可以在服务器上键入命令 su git,然后键入 gitea,如果它正常工作,您应该不会看到任何响应,也不会出现错误。 现在,一旦您进入 gitea UI 并添加了 key (与上面步骤 2-3 中使用的 key 不同,而是普通计算机上的 key ),您应该能够从非服务器运行 git 命令计算机,使用 ssh pull/推等。

关于windows - 为什么gitea添加了ssh还需要密码登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60136024/

相关文章:

windows - Windows 上的 Eclipse 和远程集群上的 Hadoop

git - 如何匿名提交对 Git 存储库的更改

git - 如何在提交前撤销 git add

python - 在 Windows 上安装 python ssh 库很困难(ssh 已替换为 "paramiko")

windows - 如何在后台从命令行启动 GUI 应用程序?

java - 从 java 更新 ldap

linux - Expect 的 "spawn"命令不支持 "spawn scp -r/home/user/dir1/* server:"中的 shell 通配符

linux - 使用 bash 脚本到 ssh 远程机器时找不到命令

c++ - 为什么操作系统更改了我的数据包的分配出站端口?

git - 是否有可能让 git 忽略损坏的 blob