- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 com.jcraft.jsch.JSch 创建 SFTP 连接。
我的 SSH key 已设置为无需用户名或密码即可直接 SSH 到服务器的位置。
ssh test_server
我的公钥位于 me@test_server:~/.ssh/
的authorized_key 文件中
我本地计算机上的 SSH key 位于 C:\cygwin\home\me\.ssh\
此外,我在该目录中还有一个配置文件和一个 known_hosts
文件。
Host test_server
User user_name
HostName test_server.domain.com
ForwardAgent yes
为了仔细检查,我确保 C:\cygwin\home\me\.ssh
中的公钥位于远程服务器的 authorized_keys
文件中。
我正在开发一个创建文件的 GUI 程序。有了该文件,我希望能够将其存储在远程服务器上,并通过 SFTP 将其放置在该文件夹中。我怎样才能做到这一点?
这是我到目前为止所拥有的:
public static void main(String[] arg) {
try {
JSch jsch = new JSch();
String user = "";
String host = "test_server";
int port = 22;
String privateKey = "C:/cygwin/home/me/.ssh/id_rsa";
jsch.addIdentity(privateKey);
System.out.println("identity added ");
Session session = jsch.getSession("", host);
System.out.println("session created.");
session.connect();
System.out.println("session connected.....");
Channel channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
System.out.println("shell channel connected....");
ChannelSftp c = (ChannelSftp) channel;
String fileName = "test.txt";
c.put(fileName, "./in/");
c.exit();
System.out.println("done");
} catch (Exception e) {
System.err.println(e);
}
}
我不断收到
com.jcraft.jsch.JSchException: Auth fail error.
有人知道这个问题的解决办法吗?
其他信息(这可能有用......不确定):
当我打开 cmd 时,它会将我带到 C:\Users\me
。
但是当我传递“pwd”命令时,它会打印出 /cygdrive/c/Users/me
。
我也对任何新的库持开放态度,或者也许只是一种更好的方法来做到这一点。
非常感谢!
ssh -v test_server
的输出:
OpenSSH_7.4p1, OpenSSL 1.0.2k 26 Jan 2017
debug1: Reading configuration data /home/me/.ssh/config
debug1: /home/me/.ssh/config line 1: Applying options for *
debug1: /home/me/.ssh/config line 9: Applying options for wmpos1
debug1: Control socket "/home/me/.ssh/master-user_name@test_server:22" d
oes not exist
debug1: Connecting to test_server [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/me/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/me/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to test_server:22 as 'user_name'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com comp
ression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com comp
ression: none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:aV1o2Laclf7vRU2QOH+iWpuYYmy2
bokk8uQrVEaPL8k
debug1: Host 'test_server' is known and matches the ECDSA host key.
debug1: Found key in /home/me/.ssh/known_hosts:2
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/me/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 151
debug1: Authentication succeeded (publickey).
Authenticated to test_server ([127.0.0.1]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
最佳答案
您没有在 ssh
命令行上显式指定用户名这一事实并不意味着不使用用户名。
默认情况下,ssh
隐式使用本地用户名。 JSch不会这样做。您必须显式指定用户名,即使它与本地用户名相同。
关于java - 使用 JSch 无需用户名或密码即可连接到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43593759/
我正在使用 jsch 进行 sftp 文件传输。当我通过设置缓冲区大小 512(-B 选项)sftp B 512 [sftp 服务器名称] 并调用 put 命令使用 sftp 命令发送文件时,我可以以
我正在尝试使用 JSch 连接到服务器,然后执行交互式 su 命令。 你能告诉我我错过了什么吗?这些东西每次都会挂起,我认为这种行为没有任何理由。特别是在发送密码之前,我专门等待密码字符串(实际上是
在 JSch 中每个 session 可以打开多少个 channel 是否有限制?我试图打开的 channel 是“ChannelShell”类型 我收到“com.jcraft.jsch.JSchEx
我正在尝试从我的 android 手机通过 ssh 连接到 ssh 服务器。 我的进口线: import com.jcraft.jsch.*; 剩下的就在这里 try{
尝试使用 ssh key 身份验证连接到主机。下面是我的代码: package com.mkyong.common; import com.jcraft.jsch.Channel; import co
我正在将一些 java 代码移植到 GRAILS 框架中,但在导入库 (jcraft) 时不断收到此错误: import com.jcraft.jsch.ChannelSftp; import com
我编写了一个连接到远程 LINUX 计算机并执行命令的程序。我使用 jsch-0.1.42.jar 文件连接到远程计算机。我的程序运行良好并返回输出。现在我想调用方法,该方法是使用以下代码从 JSP
当使用 jsch 版本 0.1.51 连接到远程主机时,我们偶尔会在 ChannelExec 上调用 Channel.connect() 时遇到以下异常。 com.jcraft.jsch.JSchEx
GerritTrigger插件以前工作得很好,但从一个我无法确定的时间点来看,连接永远无法建立,错误消息如下:。Gerit触发器版本:2.39.0。SSH密钥是通过ssh-keygen生成的。我注意到
我正在尝试连接到我的一个 unix 服务器,但由于上述错误而失败,请有人帮忙。 JSch jsch = new JSch(); java.util.Properties configuration =
我使用他下面的代码连接到 ssh 服务器。 JSch jsch = new JSch(); Session session = jsch.getSession("username", "ip", po
我有运行 ssh 服务器的 windows 机器。我知道那台机器上的路径。让它成为 D:/Folder1/Folder2 .我正在使用 JSCH 创建 sftp channel 。但是当我尝试 cd
我正在使用 Jsch 连接 sshd 服务器,我是这方面的新手。我成功发送了非控制字符,例如 a、b ...等等。但是,我需要发送“Esc”键命令(控制字符)来执行特定任务。根据link ,我尝试了几
我无法将一台unix服务器的安全服务器连接到另一台unix服务器。通过ssh从putty我可以轻松连接,但从jsch连接时出现以下错误。 成功putty步骤->在putty中连接server1->成功
我的命令有第一部分,其结果通过管道传输到第二部分。当我运行代码时,我总是返回第一部分的结果,而第二部分应用的过滤器显然没有执行。 所以我得到: CONTAINER ID IMAGE COMMAN
我正在尝试使用 JSCH 库通过 SSH 执行多个命令。我面临一个奇怪的问题。当我尝试在 Eclipse 中运行该程序时,代码完成了执行,但命令(mkdir test)未在服务器中执行但是当我一步步调
我正在使用 JSCH 通过 SSH 访问主机,然后启动一些命令。 主机未使用“通用”操作系统,因为它是 BNG:http://en.wikipedia.org/wiki/Border_Network_
好吧,我收到 UnknownHostKey 异常。我不想像这篇文章 com.jcraft.jsch.JSchException: UnknownHostKey 那样使用 StrictHostKeyCh
我正在使用 JSch 执行 sftp get 操作。当我使用 main 方法运行测试时,一切都很好,但使用单元测试时我遇到了问题。错误如下: java.lang.RuntimeException: c
我正在使用 Jsch lib 访问网络中的路由器,但在某些路由器中存在登录横幅。所以我需要读取输出,识别横幅,将其删除并仅获取命令的输出。我正在执行模式下使用 channel 。我认为的一个解决方案是
我是一名优秀的程序员,十分优秀!