Modify the following class to connect to the SSH server you configured:import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPEngine;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
public class SSHTest {
public static void main(String[] args) throws Exception {
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect("127.0.0.1", 22);
ssh.authPassword("test", "test");
SFTPClient sftp = ssh.newSFTPClient();
sftp.close();
ssh.disconnect();
}
}
Compile and run the class.
Can anyone tell me if the sshClient is threadsafe?
I am working with the version 0.5 of sshj, and I wanted to create an objectPool with the jakarta common pool api, and I need it to know if it is threadsafe?
Thanks by advance for your help
I'd like to capture all sent and received data.. Could you tell me how should I do it? How to get the right streams?
Pretty sure this is not a bug, but since I receive a permission denied when creating a remote dir, whilst it is possible to
create the directory in WinSCP I thought I should post it there. Is there something I've missed out in the initialisation?
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier("somehostkeyverifier");
ssh.loadKnownHosts();
ssh.connect(FTP_ADDRESS);
ssh.authPassword(FTP_USER, FTP_PWD);
SFTPClient sftp = ssh.newSFTPClient();
sftp.mkdir(FTP_REMOTE_DIR);
net.schmizz.sshj.sftp.SFTPException: Permission denied
at net.schmizz.sshj.sftp.Response.error(Response.java:113)
at net.schmizz.sshj.sftp.Response.ensureStatusIs(Response.java:106)
at net.schmizz.sshj.sftp.Response.ensureStatusPacketIsOK(Response.java:99)
at net.schmizz.sshj.sftp.SFTPEngine.makeDir(SFTPEngine.java:166)
at net.schmizz.sshj.sftp.SFTPEngine.makeDir(SFTPEngine.java:171)
at net.schmizz.sshj.sftp.SFTPClient.mkdir(SFTPClient.java:87)
DEBUG level on net.schmizz
2012-02-08 10:24:02 Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
2012-02-08 10:24:02 Client identity string: SSH-2.0-SSHJ_0_8
2012-02-08 10:24:02 Server identity string: SSH-2.0-mod_sftp/0.9.7
2012-02-08 10:24:02 Setting <<kex done>> to `null`
2012-02-08 10:24:02 Sending SSH_MSG_KEXINIT
2012-02-08 10:24:02 Received SSH_MSG_KEXINIT
2012-02-08 10:24:02 Setting <<kexinit sent>> to `SOME`
2012-02-08 10:24:02 Awaiting <<kex done>>
2012-02-08 10:24:02 Negotiated algorithms: [ kex=diffie-hellman-group14-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
2012-02-08 10:24:02 Sending SSH_MSG_KEXDH_INIT
2012-02-08 10:24:02 Received kex followup data
2012-02-08 10:24:02 Received SSH_MSG_KEXDH_REPLY
2012-02-08 10:24:02 Trying to verify host key with net.schmizz.sshj.SSHClient$1@3429ace1
2012-02-08 10:24:02 Sending SSH_MSG_NEWKEYS
2012-02-08 10:24:02 Received SSH_MSG_NEWKEYS
2012-02-08 10:24:02 Setting <<kexinit sent>> to `null`
2012-02-08 10:24:02 Setting <<kex done>> to `SOME`
2012-02-08 10:24:02 Key exchange took 0.284 seconds
2012-02-08 10:24:04 Setting <<service accept>> to `null`
2012-02-08 10:24:04 Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
2012-02-08 10:24:04 Awaiting <<service accept>>
2012-02-08 10:24:04 Setting <<service accept>> to `SOME`
2012-02-08 10:24:04 Setting active service to ssh-userauth
2012-02-08 10:24:04 Trying `password` auth...
2012-02-08 10:24:04 Setting <<authenticated>> to `null`
2012-02-08 10:24:04 Requesting password for [AccountResource] theserver@someserveeeer
2012-02-08 10:24:04 Awaiting <<authenticated>>
2012-02-08 10:24:04 Setting <<authenticated>> to `SOME`
2012-02-08 10:24:04 `password` auth successful
2012-02-08 10:24:04 Setting active service to ssh-connection
2012-02-08 10:24:05 Attaching `session` channel (#0)
2012-02-08 10:24:05 Awaiting <<chan#0 / open>>
2012-02-08 10:24:05 Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=4294967295] >
2012-02-08 10:24:05 Setting <<chan#0 / open>> to `SOME`
2012-02-08 10:24:05 Will request `sftp` subsystem
2012-02-08 10:24:05 Sending channel request for `subsystem`
2012-02-08 10:24:05 Awaiting <<chan#0 / chanreq for subsystem>>
2012-02-08 10:24:05 Setting <<chan#0 / chanreq for subsystem>> to `SOME`
2012-02-08 10:24:05 Consuming by 9 down to 4294967286
2012-02-08 10:24:05 Consuming by 124 down to 2097028
2012-02-08 10:24:05 Server version 3
2012-02-08 10:24:05 Sending Request{1;OPENDIR}
2012-02-08 10:24:05 Consuming by 14 down to 4294967272
2012-02-08 10:24:05 Awaiting <<sftp / 1>>
2012-02-08 10:24:05 Consuming by 19 down to 2097009
2012-02-08 10:24:05 Received HANDLE packet
2012-02-08 10:24:05 Setting <<sftp / 1>> to `Buffer [rpos=5, wpos=15, size=15]`
2012-02-08 10:24:05 Sending Request{2;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967253
2012-02-08 10:24:05 Awaiting <<sftp / 2>>
2012-02-08 10:24:05 Consuming by 313 down to 2096696
2012-02-08 10:24:05 Received NAME packet
2012-02-08 10:24:05 Setting <<sftp / 2>> to `Buffer [rpos=5, wpos=309, size=309]`
2012-02-08 10:24:05 Sending Request{3;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967234
2012-02-08 10:24:05 Awaiting <<sftp / 3>>
2012-02-08 10:24:05 Consuming by 37 down to 2096659
2012-02-08 10:24:05 Received STATUS packet
2012-02-08 10:24:05 Setting <<sftp / 3>> to `Buffer [rpos=5, wpos=33, size=33]`
2012-02-08 10:24:05 Closing `RemoteResource{.}`
2012-02-08 10:24:05 Sending Request{4;CLOSE}
2012-02-08 10:24:05 Consuming by 19 down to 4294967215
2012-02-08 10:24:05 Awaiting <<sftp / 4>>
2012-02-08 10:24:05 Consuming by 28 down to 2096631
2012-02-08 10:24:05 Received STATUS packet
2012-02-08 10:24:05 Setting <<sftp / 4>> to `Buffer [rpos=5, wpos=24, size=24]`
2012-02-08 10:24:05 Sending Request{5;OPENDIR}
2012-02-08 10:24:05 Consuming by 14 down to 4294967201
2012-02-08 10:24:05 Awaiting <<sftp / 5>>
2012-02-08 10:24:05 Consuming by 19 down to 2096612
2012-02-08 10:24:05 Received HANDLE packet
2012-02-08 10:24:05 Setting <<sftp / 5>> to `Buffer [rpos=5, wpos=15, size=15]`
2012-02-08 10:24:05 Sending Request{6;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967182
2012-02-08 10:24:05 Awaiting <<sftp / 6>>
2012-02-08 10:24:06 Consuming by 313 down to 2096299
2012-02-08 10:24:06 Received NAME packet
2012-02-08 10:24:06 Setting <<sftp / 6>> to `Buffer [rpos=5, wpos=309, size=309]`
2012-02-08 10:24:06 Sending Request{7;READDIR}
2012-02-08 10:24:06 Consuming by 19 down to 4294967163
2012-02-08 10:24:06 Awaiting <<sftp / 7>>
2012-02-08 10:24:06 Consuming by 37 down to 2096262
2012-02-08 10:24:06 Received STATUS packet
2012-02-08 10:24:06 Setting <<sftp / 7>> to `Buffer [rpos=5, wpos=33, size=33]`
2012-02-08 10:24:06 Closing `RemoteResource{.}`
2012-02-08 10:24:06 Sending Request{8;CLOSE}
2012-02-08 10:24:06 Consuming by 19 down to 4294967144
2012-02-08 10:24:06 Awaiting <<sftp / 8>>
2012-02-08 10:24:06 Consuming by 28 down to 2096234
2012-02-08 10:24:06 Received STATUS packet
2012-02-08 10:24:06 Setting <<sftp / 8>> to `Buffer [rpos=5, wpos=24, size=24]`
2012-02-08 10:24:16 Sending Request{9;MKDIR}
2012-02-08 10:24:16 Consuming by 21 down to 4294967123
2012-02-08 10:24:16 Awaiting <<sftp / 9>>
2012-02-08 10:24:16 Consuming by 43 down to 2096191
2012-02-08 10:24:16 Received STATUS packet
2012-02-08 10:24:16 Setting <<sftp / 9>> to `Buffer [rpos=5, wpos=39, size=39]`
2012-02-08 10:25:40 Dying because - net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Default disconnect listener - UNKNOWN
2012-02-08 10:25:40 Got notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Channel #0 got notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Forgetting `session` channel (#0)
2012-02-08 10:25:40 Setting <<chan#0 / close>> to `SOME`
2012-02-08 10:25:40 Setting active service to null-service
2012-02-08 10:25:40 Setting <<transport close>> to `SOME`
2012-02-08 10:25:40 Stopping
Reported by several people. Non-deterministic, but can be reproduced by trying to connect in a loop loads of times.
net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:156)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:372)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:475)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
I use quartz concurrent execute multi trigger, sometime has happen below error
[11/09/30 15:20:30][ERROR][net.schmizz.sshj.transport.TransportImpl-570] Dying because - net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received response to channel request when none was requested
[11/09/30 15:20:30][ERROR][net.schmizz.concurrent.Promise-171] <<chan#7 / chanreq for exec>> woke to: net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received response to channel request when none was requested
I open once connection , start multi session, exec command by one job
my code :
ssh = new SSHClient();
ssh.setTimeout(sshTimeout);
ssh.addHostKeyVerifier(
new HostKeyVerifier() {
@Override
public boolean verify(String arg0, int arg1, PublicKey arg2) {
return true; // don't bother verifying
}
}
);
ssh.connect(ip, port);
ssh.authPassword(username, password);
public List<String> send(String command){
String result = "";
try {
Session session = ssh.startSession();
try {
session.allocatePTY("vt100", 1024, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));
Command cmd = session.exec(command);
cmd.join(cmdTimeout, TimeUnit.MILLISECONDS);
result = IOUtils.readFully(cmd.getInputStream()).toString();
cmd.close();
}catch(Exception e){
log.error(" ip : " + ip + " send '" + command + "' command error, message is : " + e);
}finally {
session.close();
}
}catch(Exception e){
log.error(" ip : " + ip + " session close error, message is : " + e);
}
}
This works on my dev box but not on our server.
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
Here's the output:
[junit] Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
[junit] Client identity string: SSH-2.0-SSHJ_0_6_0
[junit] Server identity string: SSH-2.0-OpenSSH_4.3
[junit] Setting <<kex done>> to `null`
[junit] Sending SSH_MSG_KEXINIT
[junit] Setting <<kexinit sent>> to `SOME`
[junit] Awaiting <<kex done>>
[junit] Received SSH_MSG_KEXINIT
[junit] Negotiated algorithms: [ kex=diffie-hellman-group1-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
[junit] Sending SSH_MSG_KEXDH_INIT
[junit] Received kex followup data
[junit] Received SSH_MSG_KEXDH_REPLY
[junit] Trying to verify host key with net.schmizz.sshj.transport.verification.OpenSSHKnownHosts@5e9de959
[junit] Sending SSH_MSG_NEWKEYS
[junit] Received SSH_MSG_NEWKEYS
[junit] Setting <<kexinit sent>> to `null`
[junit] Setting <<kex done>> to `SOME`
[junit] Key exchange took 0.107 seconds
[junit] Attempting to load key from: /var/go/.ssh/id_rsa
[junit] Could not load keys due to: {}
[junit] net.schmizz.sshj.common.SSHException: No provider available for OpenSSH key file
[junit] at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:482)
[junit] at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:438)
[junit] at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:348)
[junit] at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:282)
[junit] at com.tws.util.SSH.exec(SSH.java:29)
[junit] at com.tws.cloud.ReverseProxyTest.cleanUpProxyRules(ReverseProxyTest.java:44)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:597)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
[junit] at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
[junit] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:420)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1339)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:831)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
[junit] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[junit] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:597)
[junit] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[junit] at org.apache.tools.ant.Task.perform(Task.java:348)
[junit] at org.apache.tools.ant.Target.execute(Target.java:357)
[junit] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[junit] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[junit] at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[junit] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[junit] at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[junit] at org.apache.tools.ant.Main.runBuild(Main.java:758)
[junit] at org.apache.tools.ant.Main.startAnt(Main.java:217)
[junit] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[junit] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Hi,
sometimes while Transmitting large files via SCP i recive following Error:
Caused by: net.schmizz.sshj.common.SSHException: Window consumed to below 0
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:56)
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:49)
at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:572)
at net.schmizz.sshj.transport.Reader.run(Reader.java:79)
Caused by: net.schmizz.sshj.common.SSHRuntimeException: Window consumed to below 0
at net.schmizz.sshj.connection.channel.Window.consume(Window.java:59)
at net.schmizz.sshj.connection.channel.ChannelInputStream.receive(ChannelInputStream.java:154)
at net.schmizz.sshj.connection.channel.AbstractChannel.receiveInto(AbstractChannel.java:364)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:182)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:125)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:474)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Sorry but i do not understand the reason why this error occurs. Neither do i have any idea how to solve it.
I'm not sure if this is an bug or not. But i definitely can't pin down a reason why this exception happens.
just like in the issue #18 that was closed, the issue still remains for the version 0.5.0 of sshj.
Here is the log that I obtain:
12:51:45,040 [reader] ERROR (net.schmizz.sshj.transport.TransportImpl:570) - Dying because - net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
12:51:45,047 [AsyncTask] ERROR (net.schmizz.concurrent.Promise:171) - <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
12:51:45,048 [AsyncTask] ERROR (FW:75) - class com.orange.fcr.business.impl.AsynchronousTicketHandler:An exception happend while running task DeleteAddress:InitTerminalTask
com.orange.fcr.business.TaskException: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
at com.orange.fcr.business.task.InitTerminalTask.run(InitTerminalTask.java:39)
at com.orange.fcr.business.impl.BaseAbstractTicketHandler.run(BaseAbstractTicketHandler.java:37)
at com.orange.fcr.business.impl.AsynchronousTicketHandler.executeCommand(AsynchronousTicketHandler.java:99)
at com.orange.fcr.business.impl.AsynchronousTicketHandler.access$200(AsynchronousTicketHandler.java:24)
at com.orange.fcr.business.impl.AsynchronousTicketHandler$AsynchronousTask$1.call(AsynchronousTicketHandler.java:119)
at com.orange.fcr.business.impl.AsynchronousTicketHandler$AsynchronousTask$1.call(AsynchronousTicketHandler.java:117)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.lang.Thread.run(Thread.java:662)
Caused by: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:152)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:372)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:477)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Does anyone have an idea about it?
- can try with slf4j-android
- apparently android includes bouncycastle?
hi,
while using sshj against openssh with rport forwarding enabled
sshClient.getRemotePortForwarder().bind(new Forward(p), new SocketForwardingConnectListener(new InetSocketAddress("localhost", localPort)));
i am getting a lot of disconnects (after some minutes, but never got it to an hour)
server log:
Jan 12 14:37:43 catbox sshd[11984]: channel_by_id: 4: bad id: channel free
Jan 12 14:37:43 catbox sshd[11984]: Disconnecting: Received data for nonexistent channel 4.
client log:
2012-01-12 14:37:11,235 ERROR [net.schmizz.sshj.transport.TransportImpl] Dying because - net.schmizz.sshj.transport.TransportException: [PROTOCOL_ERROR] Disconnected; server said: Received data for nonexistent channel 4.
2012-01-12 14:37:20,785 ERROR [net.schmizz.sshj.common.StreamCopier] In pipe from java.net.SocketInputStream@4434d2ab to < ChannelOutputStream for Channel #0 >: net.schmizz.sshj.transport.TransportException: Broken pipe
2012-01-12 14:37:20,785 ERROR [net.schmizz.sshj.transport.TransportImpl] Dying because - net.schmizz.sshj.transport.TransportException: Broken pipe
2012-01-12 14:37:20,786 ERROR [net.schmizz.concurrent.Promise] <<copyDone>> woke to: net.schmizz.sshj.transport.TransportException: Broken pipe
note: log timestamps don't fit because one hosts clock is off some seconds
edit: changed title to reflect severity
I'm trying to change the terminal window size on the fly with shell.changeWindowDimensions(int, int, int, int) but it doesn't seem to have any effect. I initially set the window size with:
session.allocatePTY("ansi", 80, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));
The above code works to initialize the window size and set the terminal type, however, subsequent calls to changeWindowDimensions don't work. Perhaps I am using the method incorrectly?
My full snippet of code looks like:
// Create a session
session = client.startSession();
// Create a PTY with default size
session.allocatePTY("ansi", 80, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));
// Create a shell
final Shell shell = session.startShell();
// Now attempt to change the window size
shell.changeWindowDimensions(80, 48, 640, 960);
I am having a problem when ever I try to execute a command that requires sudo access. The commands work fine without sudo, but as soon as the command is prefixed with sudo, it will not work. I have run the exact same commands on the actual remote server and they work fine, but over sshj they don't.
- advisable anyway
- can use BC features with impunity
We're running into the following issue:
- Client using sshj begins file transfer.
- File entry appears on SFTP server.
- Server process moves the file to another location as soon as it sees the file.
- Client using sshj completes the file transfer.
- Client using sshj sends command to set file attributes it sees locally on the remote file, but it doesn't exist at the same path on the server. Throws a "No such file" SFTPException.
It seems like sshj should either:
- Have the option to disable step 5.
- Separate these FTP commands. If someone needs to duplicate local file attributes, they should also send a request for that. If not, then they shouldn't be forced to.
See net.schmizz.sshj.sftp.SFTPFileTransfer.Uploader.upload(). engine.setAttributes() is what throws the SFTPException in step 5.
Summary: Cannot get the pre-login banner from my RHEL 5 & Centos 5 servers.
Remote systems: RHEL 5 & Centos 5 systems running OpenSSH 4.3p2.
Remote sys config: Password based authentication - default RHEL 5 / CentOS 5 w/ "Banner /etc/ssh/sshd_banner.txt" config in /etc/ssh/sshd_config. The file sshd_banner.txt is a simple text file.
Description:
I am trying to get the banner multiple times during the different stages of session startup and even before teardown using
ssh.getUserAuth().getBanner() where ssh is an instance of SSHClient.
The getBanner() method always comes back as "" instead of the null that is mentioned in the documentation:
https://github.com/shikhar/sshj/blob/master/src/main/java/net/schmizz/sshj/userauth/UserAuth.java#L52
That is because it is initialized to "" here: https://github.com/shikhar/sshj/blob/master/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java#L46
The documentation issue is a minor one at this point. I can see the banner fine with the openssh client. I tried JSch as well and the banner is available when connecting with JSch.
At this point I am not even sure, that the banner is actually sent when connecting with sshj. Before I spend more time on debugging this problem further, I want to make sure I am not missing something. Anyone else having problems with this?
Update 1
I tried connecting to an OpenBSD 5.0 system running OpenSSH 5.9. Interestingly, the pre-login banner is shown by the 5.9 server. It seems the message sequence used by sshj is tripping up the OpenSSH 4.3 server and it is not sending the banner. But why is the message sequence used by sshj different from the OpenSSH client or JSch?
Update 2
I dug deeper and I found that not seeing a pre-auth banner on OpenSSH 4.3 actually is caused by the server not sending one. Apparently in OpenSSH 4.3 the pre-auth banner is only sent if the client requests authentication method "none". The OpenSSH team fixed that issue no too long after 4.3 (http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/auth2.c#rev1.117) but the fix never made it into the RHEL 5 sources.
For test purposes I inserted a call to AuthNone in UserAuthImpl.authenticate() before the main loop through the authentication methods and the banner showed up.
There is another issue in sshj. While looking through the authenticate method, I noticed that sshj does not seem to take into account the allowed methods by the server. It should really make that call to AuthNone first, take the server accepted out of the reply and populate the allowedMethods HashSets with that instead of just populating it based on the methods passed in by the user. Using the "none" method to get the allowed methods seems to be the standard way to do this in other SSH clients but is not mandated in RFC 4252.
Hi,
I need to read a file's contents, changed file contents, periodically reading only the changed contents from last read. I tried to use RandomAccessRemoteFile but it was too slow. Reading an entire file thru RandomAccessRemoteFile is about 100 times slower than reading the entire file using RemoteFile. Even reading changed contents (few lines) isn't fast enough.
Is there any way to get this to work faster?
Regards,
Prakash
version 0.6.1
This code works fine:
ssh.newSCPFileTransfer().download("/home/test.ini", "C:/test");
But this doesn't work:
ssh.newSCPFileTransfer().download("/home/*.ini", "C:/test");
Got error message:
02:22:31.190 [main] INFO n.s.s.c.c.direct.SessionChannel - Will request to exec `scp -f -q -p -r '/home/*.ini'`
.......
Caused by: net.schmizz.sshj.xfer.scp.SCPException: Remote SCP command returned error: scp: /home/*.ini: No such file or directory
Is there any hope for commons-net-ssh to be available as a maven artifact on some well-known maven repostory (at best, one visible by the wonderful mvnbrowser site) ?
When I try to connect to a new host for the first time via SSH, I'm asked if I trust and want to add a public host key. Is there any way to do this through SSHJ, or must the known hosts file already exist? I'm working on a windows workstation, so I have to jump through hoops to get an OpenSSH known hosts file on client machines.
This file https://github.com/shikhar/sshj/blob/53ad9d2288850717bd3e48f1999a35472ae95abe/src/main/java/examples/SCPDownload.java gives:
Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:70)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:77)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:103)
at examples.SCPDownload.main(SCPDownload.java:31)
environment:
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b24~pre2-1)
OpenJDK Server VM (build 20.0-b12, mixed mode)
This is on Debian (Squeeze release)
Hi,
I am running the following code (which has been nullified for security reasons) which tries to upload a file from my Windows XP desktop machine to a Windows Server 2008 with SSH enabled.
import java.io.File;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.xfer.scp.SCPFileTransfer;
public class SSHSCP {
public static void main(String[] args)
throws IOException, ClassNotFoundException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts(new File("C:\\.ssh\\known_hosts"));
ssh.connect("test.com");
ssh.authPassword("test_user", "test_pass");
try {
SCPFileTransfer transfer = ssh.newSCPFileTransfer();
transfer.upload("C:\\test.txt", "/test");
} finally {
ssh.disconnect();
}
}
}
After using OpenSSH to create a "known_hosts" file I then run the program which produces the following error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" net.schmizz.sshj.connection.ConnectionException: Request failed
at net.schmizz.sshj.connection.channel.AbstractChannel.gotResponse(AbstractChannel.java:397)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:202)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:125)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:474)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Java Result: 1
I am able to connect fine using a third party client like PSCP.exe and the SSH server logs the fact that the above Java program successfully logs in:
SSH connection attempt.
SSH test_user successfully logged on using password.
For some strange reason it then fails to send the file. Any ideas what could be going wrong?
Thanks
Is there any interest in providing ssh agent integration, similar to that provided by Mina? This requires some sort of native library to access the unix socket (Mina use the apache runtime I believe), so would probably need to be made optional.
Any thoughts?
Hi Shikhar,
I use spring scheduler (based on quartz when tasks are executed in different threads).
So each task uploads a different file but to the same host and folder.
For example:
task1 ---------------------------------------------->
taks2 -------------------------------------------->
task3 ------------------------------------>
So as you can see when task1 is in the middle of uploading, task2 starts to upload another file to the same host and even to the same folder. It seems that all files are transfered successfully but I get strange debug logs like the below. 182% transfered! For more information I can send you full logs. I don't see how to attach files here.
DEBUG [LoggingTransferListener] transferred 182% of `XXXXXXXX.txt`
[SFTPEngine] Sending Request{2666;WRITE}
DEBUG [Window$Remote] Consuming by 32768 down to 65536
DEBUG [Promise] Awaiting <<sftp / 2666>>
most used stuff gets priority
When trying to initialize a SFTP connection I get an exception.
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier("someverifier");
ssh.loadKnownHosts();
ssh.connect(FTP_ADDRESS);
ssh.authPassword(FTP_USER, FTP_PWD);
SFTPClient sftp = ssh.newSFTPClient();
java.lang.RuntimeException: Invalid value: -1
at net.schmizz.sshj.common.Buffer.putUInt32(Buffer.java:329)
at net.schmizz.sshj.connection.channel.ChannelOutputStream$DataBuffer.flush(ChannelOutputStream.java:118)
at net.schmizz.sshj.connection.channel.ChannelOutputStream$DataBuffer.flush(ChannelOutputStream.java:98)
at net.schmizz.sshj.connection.channel.ChannelOutputStream.flush(ChannelOutputStream.java:209)
at net.schmizz.sshj.sftp.SFTPEngine.transmit(SFTPEngine.java:262)
at net.schmizz.sshj.sftp.SFTPEngine.init(SFTPEngine.java:69)
at net.schmizz.sshj.SSHClient.newSFTPClient(SSHClient.java:623)
I am using v 0.7.0 from the maven repository.
Version 0.6.1
Trying to execute a command in: BlackDiamond8810, Summit48I and SummitX480 (Extreme Networks) and all of them cause this error on log.
14 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
516 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
608 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_6_0
635 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-4.1.2 SSH Secure Shell Toolkit
635 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
656 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
708 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
842 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
844 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
875 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
875 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
881 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 0.246 seconds
910 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
911 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
911 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
1059 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
1059 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
1067 [main] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
1087 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=16384] >
1088 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request to exec `show lacp counters`
1088 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `exec`
1107 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
1107 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got EOF
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got close
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending EOF
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
1108 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
1125 [reader] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received CHANNEL_FAILURE on unknown channel #0
1126 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to null-service
the code:
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect("192.168.10.5");
try {
ssh.authPassword("user", "pass");
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("show lacp counters");
cmd.join(5, TimeUnit.SECONDS);
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
System.out.println("\nEXIT STATUS: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
In another devices, like Cisco or Juniper, this code works properly.
Thanks,
Elias
We're having issues communicating with Tectia's SSH server using the latest SSHJ client (0.7.0). Here's the test code and a dump of the error log:
import java.io.InputStream;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPEngine;
import net.schmizz.sshj.sftp.StatefulSFTPClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
import org.apache.commons.io.IOUtils;
public class SFTPTest {
public static void main(String[] args)
throws Exception {
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
client.connect("127.0.0.1", 22);
client.authPassword("test", "test");
StatefulSFTPClient sftp = new StatefulSFTPClient(new SFTPEngine(client).init());
System.out.println("File Exists: " + sftp.statExistence("test.txt"));
InputStream input = sftp.open("test.txt").getInputStream();
IOUtils.copy(input, System.out);
IOUtils.closeQuietly(input);
sftp.close();
client.close();
}
}
stdout:
File Exists: [size=14;mode=[mask=100600];atime=1326843624,mtime=1326843624;]
stderr:
317 [main] INFO net.schmizz.sshj.common.SecurityUtils - Trying to register BouncyCastle as a JCE provider
800 [main] INFO net.schmizz.sshj.common.SecurityUtils - Registration succeeded
853 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_7
856 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-6.2.3.168 SSH Tectia Server
857 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
5348 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
5395 [reader] INFO net.schmizz.sshj.transport.kex.DHG14 - Sending SSH_MSG_KEXDH_INIT
5536 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
5537 [reader] INFO net.schmizz.sshj.transport.kex.DHG14 - Received SSH_MSG_KEXDH_REPLY
5582 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
5582 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
5586 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 4.729 seconds
5588 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5707 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5707 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
5708 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
5708 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
5725 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5819 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5819 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
5819 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
5835 [main] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
5836 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5840 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=65536] >
5840 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request `sftp` subsystem
5840 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `subsystem`
5919 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [main] INFO net.schmizz.sshj.sftp.SFTPEngine - Server version 3
5935 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5935 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5937 [main] INFO net.schmizz.sshj.sftp.StatefulSFTPClient - Start dir = /C:/Documents and Settings/test
5939 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5941 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5962 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5963 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got chan request for `exit-status`
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got EOF
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5992 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got close
5992 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending EOF
5993 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
5993 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
5996 [main] ERROR net.schmizz.concurrent.Promise - <<sftp / 4>> woke to: net.schmizz.sshj.sftp.SFTPException: EOF while reading packet
Exception in thread "main" net.schmizz.sshj.sftp.SFTPException: EOF while reading packet
at net.schmizz.sshj.sftp.PacketReader.readIntoBuffer(PacketReader.java:52)
at net.schmizz.sshj.sftp.PacketReader.getPacketLength(PacketReader.java:57)
at net.schmizz.sshj.sftp.PacketReader.readPacket(PacketReader.java:67)
at net.schmizz.sshj.sftp.PacketReader.run(PacketReader.java:84)
You can grab the server here - http://www.tectia.com/en/Customers/Evaluate/Client_-_Server.iw3. I have only tested the Windows server (on XP). Setup is relatively straight forward, everything is set up straight out of the box, all you need to do is create a user named test with the password test and drop a file called "test.txt" into their home directory.
Let me know if you need any more info.
I'm using sshj in a Remote Management Client for small, Android-based devices using the dropbear ssh server on the units.
While I can execute shell scripts fine as well as download files via SCP, I cannot seem to upload files to the unit. I can use my system's scp binary fine, and I've also confirmed that sshj works when connecting to a non-dropbear server, but when executing an SCP from sshj->dropbear, the upload hangs and a 0kb file is created at the upload destination.
If you need any more information, just let me know.
javadoc is well and good but mainly you want to use a specific thing, e.g. scp, sftp, port forwarding, execute a command, ...
should setup a page/pages on the wiki walking through these use cases
Complete thorough Javadoc of all public API, and host somewhere
hi
I'm trying to upload a file to a sftp server using private key authentication. please provide one example for this. I searched for so long , I could't be able to find any help;
thanks
raghu
I try to execute two commands in one session and I receive an error "This session channel is all used up"!!!
How I can carry out some commands in one SSH sessions??
version: sshj-0.5.0.zip
My example:
client = new SSHClient();
client.addHostKeyVerifier(new HostKeyVerifier() {
public boolean verify(String s, int i, PublicKey publicKey) {
return true;
}
});
client.connect(server);
client.authPassword(userName, pass);
session = client.startSession();
exec(session, "pwd");
exec(session, "ls -l");
public void exec(Session session, String commands) throws Exception {
final Session.Command cmd = session.exec(command);
cmd.join();
InputStream in = cmd.getInputStream();
System.out.println(IOUtils.readFully(in));
InputStream er = cmd.getErrorStream();
System.out.println(IOUtils.readFully(er));
}
A deadlock occurs involving two threads: Reader thread (net.schmizz.sshj.transport.Reader) and custom thread.
- Reader thread obtains monitor in AbstractChannel.getResponse(boolean).
- Custom thread calls session.close(), which obtains the ReentrantLock in the same class as step #1.
- Custom thread calls session.sendClose() and waits for the monitor held by Reader thread.
- Reader thread waits for the ReentrantLock held by Custom thread in step #1. Therefore deadlock.
This problem occurs because Reader thread receives a Event and each Event contains the same ReentrantLock used by session.close().
We are using sshj v0.3.1. By looking at the code, this problem still exists in v0.5.0.
Here is the output from kill -3.
Found one Java-level deadlock:
"J3132-JQ455373-TS2741-QTS824034-runSshCommand":
waiting to lock monitor 0x09e16130 (object 0x9b7dfb28, a net.schmizz.sshj.connection.channel.direct.SessionChannel),
which is held by "reader"
"reader":
waiting for ownable synchronizer 0x9b7df6f8, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
which is held by "J3132-JQ455373-TS2741-QTS824034-runSshCommand"
Java stack information for the threads listed above:
"J3132-JQ455373-TS2741-QTS824034-runSshCommand":
at net.schmizz.sshj.connection.channel.AbstractChannel.sendClose(AbstractChannel.java:283)
- waiting to lock <0x9b7dfb28> (a net.schmizz.sshj.connection.channel.direct.SessionChannel)
at net.schmizz.sshj.connection.channel.AbstractChannel.close(AbstractChannel.java:259)
at XXXXXXX.core.remotecommand.ssh.RunSshCommand.runSshCommand(RunSshCommand.java:84)
at XXXXXXX.core.remotecommand.ssh.RunSshCommand.run(RunSshCommand.java:40)
at java.lang.Thread.run(Thread.java:662)
"reader":
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x9b7df6f8> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178)
at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
at net.schmizz.concurrent.Future.lock(Future.java:196)
at net.schmizz.concurrent.Future.set(Future.java:76)
at net.schmizz.concurrent.Event.set(Event.java:61)
at net.schmizz.sshj.connection.channel.AbstractChannel.gotResponse(AbstractChannel.java:373)
- locked <0x9b7dfb28> (a net.schmizz.sshj.connection.channel.direct.SessionChannel)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:198)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:122)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:452)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:126)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:189)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Found 1 deadlock.
If I do the following:
// start a shell
ssh.startSession().startShell();
// change to the /tmp/ directory
ssh.startSession().exec("cd /tmp/").join();
// print out the current directory
Command cmd = ssh.startSession().exec("pwd");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join();
Shouldn't I see the current directory as /tmp/? I thought that once you start a shell, all subsequent execs would maintain state between the calls, but I am not observing this. It seems when I try to do the above, it always looks like I stay in the initial directory. Is there something I am missing, is there another way to do this, or is this an error?
Hello.
There are several issues while sending data through sshj data_channel:
- When sshj connects to ssh server with small window size (smaller that maximum packet size)
and try to sent through data_channel data, more than this window accepts, sshj hangs
The possible explanation is sshj don't send any CHANNEL_WINDOW_ADJUST message to server and lock.wait() don't get interrupted.
- When sshj connect to ssh server and local windows size (2MB) is greater than remote window size (1MB) while writing data to that channel server recieved sshPacket with size(32777) more than maxPacketSize allows (32768) and ssh server exits and sshj exits
too.
The possible explanation to this, is that at the beggining of trans.write buffer.rpos() = 5 and buffer.wpos()=14 9 bytes that ruines sshPacket. I managed this issue by adding final int x = Math.min(len, win.getMaxPacketSize() - 9 - bufferLength). But i don`t think this is correct patch for this issue.
All tests could be done with dropbear ssh server where you could reproduce this problem
With OpenSSH everything works great
.
@ury0005:
"winsshd sends SSH_MSG_CHANNEL_OPEN_CONFIRMATION with "initial window size" less then "maximum packet size" (16384 < 35840). So SSHj try to send data block with 35840 size is waiting forever for a window size will be available."
Too strongly coupled due to inheritance.
I'm using your fine library for sftp connections, but recently I had to connect to a ancient server, that only supports protocol 2.
After checking the v3 documentation, I realized that the differences between v2 and v3 are minimal, and it's easy to add v2 support.
The following patch adds protocol v2 support. Obviuosly, this should be rewritten to check for the connection version, and only omit the status message if the connection protocol is V2, but I did not have the time to figure out how to do that. I have done some minimal testing on the code, and it works for my purposes.
diff -r shikhar-sshj-v2/src/main/java/net/schmizz/sshj/sftp/Response.java shikhar-sshj-56e135e/src/main/java/net/schmizz/sshj/sftp/Response.java
75c75
< throw new SFTPException(readStatusCode(), /*readString()*/ "Stoty meghekkelte hogy menjen v2-vel");
---
> throw new SFTPException(readStatusCode(), readString());
diff -r shikhar-sshj-v2/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java shikhar-sshj-56e135e/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java
38c38
< public static final int PROTOCOL_VERSION = 2;
---
> public static final int PROTOCOL_VERSION = 3;
Recommend Projects
-
-
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
An Open Source Machine Learning Framework for Everyone
-
The Web framework for perfectionists with deadlines.
-
A PHP framework for web artisans
-
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
Some thing interesting about web. New door for the world.
-
A server is a program made to process requests and deliver data to clients.
-
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Some thing interesting about visualization, use data art
-
Some thing interesting about game, make everyone happy.
-
Recommend Org
-
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Open source projects and samples from Microsoft.
-
Google ❤️ Open Source for everyone.
-
Alibaba Open Source for everyone
-
Data-Driven Documents codes.
-
China tencent open source team.
-