且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

com.jcraft.jsch.JSchException:java.net.ConnectException:拒绝连接:connect

更新时间:2021-11-02 09:13:55

您正尝试通过SSH协议连接到本地主机.使用JSCH,这不完全是套接字编程,但是您的问题与套接字编程有关.

You're attempting to connect to your local host via the SSH protocol. With JSCH this isn't exactly socket programming, but your issue is related to socket programming.

本质上,您的问题是您的程序试图连接到未打开的端口,特别是在这种情况下,该端口是22.您没有SSH服务器,因此SSH客户端无法执行任何操作.您正在打电话给没有电话的人.

Essentially your issue is that your program is trying to connect to a port which isn't open, specifically in this instance it's port 22. You don't have an SSH server so your SSH client can't do anything. You're making a telephone call to someone who doesn't have a phone.

要解决此问题,您需要找到上面运行ssh的测试服务器以进行开发,或者在本地PC上安装ssh服务器.对于Windows盒,***的选择是 cygwin ,这将允许您模拟posix系统并在您的计算机上运行SSHD本地机器.谷歌搜索cygwin和sshd将为您提供有关如何进行设置的示例.

To resolve this issue you need to either find a test server which does have ssh running on it to do your development against or install an ssh server on your local PC. For a windows box your best bet is cygwin, which will allow you to emulate a posix system and run SSHD on your local machine. A google search for cygwin and sshd will provide you with examples of how to set this up.