在Cygwin下使用SSHD配置公钥认证


1

我正在尝试配置SSHD以允许在Windows Server 2012上的Cygwin下进行公钥认证。目前我的问题是访问被拒绝。我已确认我的公钥在用户的.ssh目录中的authorized_keys和authorized_keys2中保存为一行。下面你会看到我用来连接的命令,我尝试使用私钥连接SSH的详细输出,以及我的SSHD配置。我试图使用的私钥是RSA PEM格式。

我也尝试在我的配置中添加RSAAuthentication Yes,但这会导致SSHD在启动时失败。

当RSAAuthentication YES在SSHD配置中时,我得到它低于错误。

cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started.

SSH连接命令

ssh -v -i id_rsa.pem <USER>@<SERVER ADDRESS>

SSHD配置

PasswordAuthentication no
UsePAM no
PubkeyAuthentication yes

详细输出

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to ec2-54-186-180-177.us-west-2.compute.amazonaws.com [54.186.180.177] port 22.
debug1: Connection established.
debug1: identity file id_rsa.pem type -1
debug1: identity file id_rsa.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA a6:a5:57:ef:09:14:7b:0b:cc:29:7b:01:fa:ac:c8:ea
debug1: Host 'ec2-54-186-180-177.us-west-2.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/cyotee/.ssh/known_hosts:6
Warning: the RSA host key for 'ec2-54-186-180-177.us-west-2.compute.amazonaws.com' differs from the key for the IP address '54.186.180.177'
Offending key for IP in /Users/cyotee/.ssh/known_hosts:5
Matching host key in /Users/cyotee/.ssh/known_hosts:6
Are you sure you want to continue connecting (yes/no)? yes
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: id_rsa.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

2
sshd并且ssh对包含私钥的文件的权限很挑剔。它们不能是组或世界可读的。我不确定这是如何转化为Cygwin的。
LawrenceC

1
你需要看一下服务器端。客户看起来运行得很好。
丹尼尔B

尝试检查服务器端的日志。它通常位于/var/log/sshd.logcygwin的内部。
Squeezy

Answers:


1

根据我的经验,问题通常是服务器端的文件权限不正确。尝试相应地修改文件权限。

chown -R USERNAME~USERNAME / .ssh

chmod 700~USERNAME / .ssh

chmod 600~USERNAME / .ssh / authorized_keys


0

如果您能告诉我们您的公钥的结尾应该是什么样的<user>@<host>,就像您的计算机上的那个(在名为<filename>.pubunder 的文件中/.ssh/)和您复制的远程服务器上的那个公钥一样,这将是非常有帮助的。进入authorized_keys),你用来连接的计算机也可以显示命令hostname输出的内容。

如果你从另一台计算机上复制了密钥,这是非常不推荐的,可能是你的问题......


公钥的最后一个字段只是一个注释。
肯斯特
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.