生成公钥和私钥后无法连接到 SSH

Vin*_*oth 5 ssh cygwin openssh

有人可以帮忙吗?我已经在 Windows 7 中安装了 openssh(版本 OpenSSH_6.8p1),并且已经生成了公钥和私钥,但是我无法连接到该 SSH。如果我使用命令“ssh localhost”,我会收到错误“连接已被 127.0.0.1 关闭”。

但是,我可以通过“ssh localhost -o PubkeyAuthentication=no”跳过公钥身份验证进行连接

命令“ssh -v localhost”的输出

OpenSSH_6.8p1、OpenSSL 1.0.2a 2015 年 3 月 19 日
debug1:读取配置数据 /etc/ssh_config
debug1:连接到 localhost [127.0.0.1] 端口 22。
debug1:已建立连接。
debug1:身份文件 /home/Vinoth/.ssh/id_rsa 类型 1
debug1:key_load_public:没有这样的文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_rsa-cert 类型 -1
debug1:key_load_public:没有这样的文件或目录目录
debug1:身份文件 /home/Vinoth/.ssh/id_dsa 类型 -1
debug1:key_load_public:没有这样的文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_dsa-cert 类型 -1
debug1:key_load_public:没有这样的文件或目录文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_ecdsa 类型 -1
debug1:key_load_public:没有这样的文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_ecdsa-cert 类型 -1
debug1:key_load_public:没有这样的文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_ed25519 类型 -1
debug1:key_load_public:没有这样的文件或目录
debug1:身份文件 /home/Vinoth/.ssh/id_ed25519-cert 类型 -1
debug1:启用协议 2.0 的兼容模式
debug1: 本地版本字符串 SSH-2.0-OpenSSH_6.8
debug1: 远程协议版本 2.0,远程软件版本 OpenSSH_6.8
debug1: match: OpenSSH_6.8 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT 已发送
debug1: SSH2_MSG_KEXINIT收到
debug1: kex: 服务器->客户
端 aes128-ctr umac-64-etm@openssh.com 无 debug1: kex: 客户端->服务器 aes128-ctr umac-64-etm@openssh.com 无
debug1: 期待 SSH2_MSG_KEX_ECDH_REPLY
debug1: 服务器主机密钥:ecdsa-sha2-nistp256 SHA256:4Lnpmdki8UuIiQtJyZoc2vxu8x9l PVSN4vykW+axilc
debug1:主机“localhost”已知并与 ECDSA 主机密钥匹配。
debug1:在 /home/Vinoth/.ssh/known_hosts:1 中找到密钥
debug1:发送 SSH2_MSG_NEWKEYS
debug1:期待 SSH2_MSG_NEWKEYS

debug1:接收 SSH2_MSG_NEWKEYS
debug1:服务器不允许漫游 debug1:
发送 SSH2_MSG_SERVICE_REQUEST
debug1:收到 SSH2_MSG_SERVICE_ACCEPT
debug1:可以继续的身份验证: publickey、password、keyboard-interactive
debug1:下一个身份验证方法:publickey
debug1:提供 RSA 公钥:/home/Vinoth/.ssh/id_rsa
连接被 127.0.0.1 关闭

.ssh文件夹下的文件列表

$ ls -lrt 总计 7 -rwxrwx--- 1 Vinoth 无 519 Jun 11 18:36known_hosts
-rw-rw---- 1 Vinoth 无 1679 Jun 12 00:48 id_rsa
-rw-rw---- 1 Vinoth 无398 六月 12 日 00:48 id_rsa.pub
-rw-rw---- 1 Vinoth 无 398 六月 12 23:47authorized_keys

/var/log 下的文件列表

$ ls -lrt
总计 54101
-rw-r--r-- 1 Vinoth 管理员 35167 Jun 11 15:10 setup.log
-rw-r--r-- 1 Vinoth 管理员 25541 Jun 11 15:10 setup.log.full
-rw----r-- 1 系统 系统 469 Jun 11 15:43 sshd.log
-rw-r--r-- 1 sshd 管理员 55330520 Jun 13 00:57 lastlog

sshd.log 没有更新。最后日志文件不可读

猫 sshd.log

Vinoth@Vinoth-HP /var/log $ cat /var/log/sshd.log /var/empty 必须由 root 所有,且不可组写入或全局写入。

bar*_*lop 1

你写

我可以通过“ssh localhost -o PubkeyAuthentication=no”跳过公钥身份验证进行连接

好的

所以$ssh-copy-id localhost

(然后应该将发布密钥从源放到远程系统〜/.ssh/authorized_keys)

出口

然后

ssh localhost

它应该直接进入,因为它会首先尝试 pub key 并且它应该可以工作。

添加

ls -l /var/log/sshd.log

看看它上次写的时间,然后 cat /var/log/sshd.log

或者我想tail /var/log/sshd.log在那里看到最后/最近的条目

添加-b

cat /var/log/sshd.log 给出“/var/empty 必须由 root 拥有,并且不可组或全局可写。”

尝试

$ chown root /var/empty
chown: 无效用户: 'root'

您可能会收到上面的错误。这可能是 cygwin/cygwin openssh 的一个奇怪之处。

所以尝试一下

(也许cygwin是荒谬的)

正如这里提到的
https://www.cygwin.com/ml/cygwin/2008-02/msg00429.html

尝试$chown SYSTEM /var/empty

如果它不起作用,那么再次 cat sshd.log 您可能会在那里收到一个新错误,这将是进步。

添加了c

你可以尝试重新开始]你可以尝试重新运行 ssh-host-config,尽管我发现我什至必须删除 sshd 服务(不仅仅是停止它),并删除 /etc 中的密钥以便 ssh-host- config 来真正配置新鲜的东西。

sc stop sshd (或 net stop sshd,或 cygrunsrv -E sshd)

sc delete sshd(或 cygrunsrv -R sshd)

rm /etc/ssh*(这些都是文件)

这可能就足够了,但你也可以这样做

net user sshd /delete

net user cyg_server /delete

从 /etc/passwd 中删除任何 sshd 或 cyg_server 用户

我看到它建议删除 /var/empty (尽管我没有,并且重新安装没问题) https://www.cygwin.com/ml/cygwin/2014-03/msg00315.html

您可以重新安装 cygwin (无需卸载),它只会更新一些内容,例如,当我这样做时,我注意到一个命令有更多开关。您安装的所有东西(例如 openssh)仍应被勾选。

我认为我不必重新启动

然后打开管理命令提示符并运行ssh-host-config ok the defaults 和 net start sshd