- 我安装了gitea(类似于gitlab)
- 我在
用户设置
->SSH KEY
中添加了有效的公钥 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 是:
- 在服务器上的 gitea 容器之外创建一个名为“git”的用户。
- 创建一个 key 对,并将其放入 git 用户的 ~/.ssh 文件夹中。
- 设置 gitea docker 卷以包含此 git 用户的 ~/.ssh 文件夹作为内部 docker 文件夹之一(即,与 gitea docker 容器的/data/共享包含 key 对的服务器的 git 用户的 ~/.ssh 文件夹) git/.ssh 文件夹
- 将 gitea 容器的 docker 用户设置为与服务器的 git 用户相同的用户 ID
- 需要将公钥添加到服务器的 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
) - 在服务器上创建一个名为 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
) - 取下 docker 容器并将其备份(从 gitea docker-compose.yml 文件所在的文件夹中,
docker-compose down
,然后docker-compose up -d
) - 在常规计算机上的命令提示符下进行测试:
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/