无法通过命令行使用SSH连接到Gitea

135次阅读
没有评论

问题描述

在使用命令行通过SSH连接到Gitea时遇到了问题。他的电脑是Windows 10 Pro 1909版本。他在办公室的一台机器上运行了一个Gitea服务器,本地IP地址为10.100.10.24,SSH配置在端口22000上。Gitea配置为使用端口3000进行HTTP访问。用户能够通过桌面访问Gitea网站,但无法通过命令行使用SSH连接到Gitea服务器。用户尝试了一些解决方法,但仍然无法解决问题。

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

SSH连接后无响应

问题可能是由于MinGW的限制导致的客户端tty问题。过去,我遇到过ssh无法在本地tty上进行ioctl的问题,因为缺少控制设备(pty)。我当时使用了winpty,但我认为较新版本的MinGW/MinGW64(通过Git安装的运行bash的Posix层)已经解决了这个问题,因为我再也没有遇到这个问题。

解决方案:
– 尝试将Windows客户端中的Git升级到最新版本(最佳选择)。
– 尝试使用GIT CMD而不是GIT BASH
– 如果您没有使用Windows上的Git组件,请尝试从命令窗口调用ssh命令。

SSH未使用您的密钥

我怀疑这是您的问题:

debug1: identity file C:\\Users\\alexa\\.ssh\\id_rsa type -1

在我的电脑上,我得到以下结果:

debug1: Reading configuration data /c/Users/xxxx/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to xxx [192.168.0.1] port 22.
debug1: Connection established.
debug1: identity file /c/Users/xxxx/.ssh/id_rsa type 0

为什么您得到的是类型-1,可能是权限问题。请确保C:\Users\alexaC:\Users\alexa\.sshC:\Users\alexa\.ssh\id_rsa的所有权限只有SYSTEMalexaAdministrators

另外,请注意您的日志中出现了双反斜杠(例如C:\\Users\\alexa\\.ssh\\id_rsa),而不是单反斜杠(C:\Users\alexa\.ssh\id_rsa)。我的日志中没有双反斜杠。

方案2

根据您提供的信息,您可能需要以另一种方式安装Gitea。错误消息给出了一些提示:

and setup Gitea under another user

文档中提到:

Gitea should be run with a dedicated non-root system account on UNIX-type systems. Note: Gitea manages the ~/.ssh/authorized_keys file. Running Gitea as a regular user could break that user’s ability to log in.

请检查系统要求,确保按照要求在另一个用户下设置Gitea。

请注意,这个解决方案是基于您的问题描述和提供的回答。如果问题仍然存在,请提供更多详细信息以便我们能够更好地帮助您解决问题。

正文完