如何在没有密码的情况下使用SSH身份验证连接到Windows SFTP服务器?

我尝试了其他选项:

JSch jSch = new JSch();
try {
     jSch.setKnownHosts("C:/Users/User/.ssh/known_hosts");
     jSch.addIdentity("C:/Keys/id_rsa","pass");
     Session session = jSch.getSession("test","127.0.0.1",22);
     session.connect();
//   Channel channel = session.openChannel("sftp");
} catch (JSchException e) {
     e.printStackTrace();
}

我有一个本地服务器OpenSSH,安装后,它会在目录C:\ programdata \ ssh中生成几对SSH密钥(主机)。

然后,我使用PuTTYgen程序自己生成了三个密钥(用户):privat,public和authorized_keys。将authorized_keys密钥放置在服务器上的〜/ directory.ssh /中。

在使用SFTP客户端时,FileZilla和WinSCP指定了其专用用户密钥的路径并设法成功连接,但是在连接之前,您需要接受主机密钥。 但是在服务中无法连接。

jSch.setKnownHosts ("‪C:/Users/User/.ssh/known_hosts") doesn't help.

我使用了命令:

    ssh-keyscan 127.0.0.1 >> ~/.ssh/known_hosts
在PowerShell中

生成“ known_hosts”文件。 该文件包含三行:

127.0.0.1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBK5r69e63KfNv/QYrrbaxqsDupXy5vYdTrul6Hh+4ZxpIvPOemdWkdDI26RK2Kh2FSkDJiBlItzsy14ZXVXT6/k=
127.0.0.1 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq2cC2f1vPiiobWIEofDEK7noSs1Pl7nqkzz1Qe0Q0wactekHq3xf3rUGScw58gX/8hm2XquDhj2k/oSK+STU4llCSJ9z1MVIifL+deXh3KF9BboRbHpNGH4tMwuxqL/EppBEkwNup9nf2u9icrBwuyvb93Go4aLEGzlLCbuxubX2r0Da+NLqq1v4NjIkwq9a7xLHTvoP3Z7VZ1K0kS9arLdGRojL1u97hZ2D6qETWYyGpK4ppMdDUqc7IEijsY5ojQ1NZa4hmxqI3og5nNyNTUfbmUmXGjy5aXN8XXbvWcdrlU27TWdy/Zb+Z0F3xcfXln8ufJUWW4aQJno320R8Z
127.0.0.1 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK2W2zOC06JQ37+2a3pBJsWruW1/FpqWpyd/yuTmUFY6

我尝试使用文件'known_hosts'的不同变体启动服务,但这没有提供解决方案。

我使用安装了OpenSSH服务器,PowerShell和我的应用程序的同一帐户。 “〜/ .ssh / known_hosts”指向路径“ C:/Users/User/.ssh/known_hosts”。

com.jcraft.jsch.JSchException: UnknownHostKey: 127.0.0.1. RSA key fingerprint is 17:5a:76:22:e4:f2:80:69:b1:49:53:62:60:1c:fd:af
at com.jcraft.jsch.Session.checkHost(Session.java:805)
at com.jcraft.jsch.Session.connect(Session.java:345)
at com.jcraft.jsch.Session.connect(Session.java:183)
at com.example.demo.controller.Controller.writeCat(Controller.java:96)

日志文件:

Connecting to 127.0.0.1 port 22
Connection established
Remote version string: SSH-2.0-OpenSSH_for_Windows_7.7
Local version string: SSH-2.0-JSCH-0.1.54
CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
SSH_MSG_KEXINIT sent
SSH_MSG_KEXINIT received
kex: server: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1
kex: server: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
kex: server: chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
kex: server: chacha20-poly1305@openssh.com,aes256-gcm@openssh.com
kex: server: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
kex: server: umac-64-etm@openssh.com,hmac-sha1
kex: server: none
kex: server: none
kex: server: 
kex: server: 
kex: client: ecdh-sha2-nistp256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp521
kex: client: aes128-ctr,3des-cbc,blowfish-cbc,aes256-cbc
kex: client: aes128-ctr,aes256-cbc
kex: client: hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
kex: client: hmac-md5,hmac-md5-96
kex: client: none
kex: client: none
kex: client: 
kex: client: 
kex: server->client aes128-ctr hmac-sha1 none
kex: client->server aes128-ctr hmac-sha1 none
SSH_MSG_KEX_ECDH_INIT sent
expecting SSH_MSG_KEX_ECDH_REPLY
ssh_rsa_verify: signature true
Disconnecting from 127.0.0.1 port 22
zchyqwerty 回答:如何在没有密码的情况下使用SSH身份验证连接到Windows SFTP服务器?

原来是以这种方式连接的:

jSch.setKnownHosts(new ByteArrayInputStream("127.0.0.1 ssh-rsa AAAAB3Nza...".getBytes()));

非常感谢Martin Prikryl提供的检查jSch.getHostKeyRepository()。getHostKey()的建议

本文链接:https://www.f2er.com/3166255.html

大家都在问