jsch-users Mailing List for JSch (Page 5)
Status: Alpha
Brought to you by:
ymnk
You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(17) |
Nov
(3) |
Dec
(5) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(34) |
Feb
(70) |
Mar
(18) |
Apr
(17) |
May
(21) |
Jun
(20) |
Jul
(27) |
Aug
(12) |
Sep
(10) |
Oct
(7) |
Nov
(21) |
Dec
(5) |
| 2004 |
Jan
(18) |
Feb
(13) |
Mar
(35) |
Apr
(8) |
May
(26) |
Jun
(32) |
Jul
(19) |
Aug
(37) |
Sep
(14) |
Oct
(20) |
Nov
(41) |
Dec
(48) |
| 2005 |
Jan
(44) |
Feb
(60) |
Mar
(62) |
Apr
(42) |
May
(26) |
Jun
(55) |
Jul
(29) |
Aug
(21) |
Sep
(56) |
Oct
(20) |
Nov
(17) |
Dec
(9) |
| 2006 |
Jan
(33) |
Feb
(49) |
Mar
(27) |
Apr
(27) |
May
(67) |
Jun
(28) |
Jul
(64) |
Aug
(45) |
Sep
(39) |
Oct
(52) |
Nov
(36) |
Dec
(45) |
| 2007 |
Jan
(60) |
Feb
(44) |
Mar
(57) |
Apr
(18) |
May
(15) |
Jun
(37) |
Jul
(27) |
Aug
(32) |
Sep
(48) |
Oct
(52) |
Nov
(48) |
Dec
(17) |
| 2008 |
Jan
(28) |
Feb
(6) |
Mar
(29) |
Apr
(27) |
May
(10) |
Jun
(33) |
Jul
(27) |
Aug
(15) |
Sep
(46) |
Oct
(18) |
Nov
(10) |
Dec
(8) |
| 2009 |
Jan
(22) |
Feb
(17) |
Mar
(10) |
Apr
(14) |
May
(20) |
Jun
(28) |
Jul
(9) |
Aug
(8) |
Sep
(12) |
Oct
(22) |
Nov
(23) |
Dec
(18) |
| 2010 |
Jan
(32) |
Feb
(18) |
Mar
(30) |
Apr
(54) |
May
(25) |
Jun
(22) |
Jul
(26) |
Aug
(54) |
Sep
(15) |
Oct
(24) |
Nov
(53) |
Dec
(11) |
| 2011 |
Jan
(45) |
Feb
(40) |
Mar
(47) |
Apr
(28) |
May
(30) |
Jun
(58) |
Jul
(13) |
Aug
(27) |
Sep
(41) |
Oct
(7) |
Nov
(18) |
Dec
(22) |
| 2012 |
Jan
(36) |
Feb
(71) |
Mar
(30) |
Apr
(25) |
May
(32) |
Jun
(15) |
Jul
(12) |
Aug
(8) |
Sep
(16) |
Oct
(21) |
Nov
(4) |
Dec
|
| 2013 |
Jan
(9) |
Feb
(6) |
Mar
(27) |
Apr
(16) |
May
(16) |
Jun
(10) |
Jul
(5) |
Aug
(1) |
Sep
(7) |
Oct
(12) |
Nov
(25) |
Dec
(10) |
| 2014 |
Jan
(4) |
Feb
(24) |
Mar
(7) |
Apr
(12) |
May
(14) |
Jun
(7) |
Jul
(13) |
Aug
(3) |
Sep
(21) |
Oct
(10) |
Nov
(4) |
Dec
(6) |
| 2015 |
Jan
(8) |
Feb
(8) |
Mar
(6) |
Apr
(5) |
May
(2) |
Jun
(4) |
Jul
(2) |
Aug
|
Sep
(2) |
Oct
(16) |
Nov
(6) |
Dec
(9) |
| 2016 |
Jan
(7) |
Feb
(7) |
Mar
(3) |
Apr
(1) |
May
(12) |
Jun
(7) |
Jul
(7) |
Aug
(6) |
Sep
(5) |
Oct
(15) |
Nov
(6) |
Dec
(1) |
| 2017 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(2) |
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(3) |
Oct
|
Nov
(3) |
Dec
|
| 2018 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(4) |
Feb
|
Mar
(2) |
Apr
(4) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(2) |
Dec
(1) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2023 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: 艾超 <aic...@fo...> - 2016-02-13 13:51:17
|
Hello there! I've been using Jsch for several months on a business project, and I've got this problem: When using ChannelExec, I can mock a SUDO execution just like in the Jsch examples ( which is using the sudo -S -p '' <command> trick ), it's totally OK and working. However as to ChannelSftp, I can't find any examples showing how to do a SUDO put/get (when of course, the sftp user on that linux box has super permission and can do sudo ... in the interactive shell ). Is there a way to do SUDO put/get using ChannelSftp ? if yes, how to do that ? Maybe it needs some modification/extension to Jsch source, but is it possible ? Any advice will be appreciated, thanks in advance. Aich, Best Regards |
|
From: Alan E. <ala...@gm...> - 2016-02-11 16:53:31
|
Anyone ever get this? I see it in the logs for a jEdit user, but i have not seen it myself. The full stack trace can be seen here: https://gist.github.com/lbtc-xxx/e32bb695572ec322ae31 It is a strange error for 2 reasons. 1. misspelling "waiting" as "wating" 2. the timeout happens immediately and does not seem like a timeout. Is there a public repository where I can do a git clone or svn checkout of the jsch source? I am having trouble getting the sourcecode archives from sourceforge today. --Alan |
|
From: Lothar K. <jo...@ki...> - 2016-02-11 12:26:54
|
Hi,
Am 10.02.2016 um 09:38 schrieb Vladimir Kvashin:
> - does jsch accept contributions? if yes, I can try fixing this
> and propose a patch
I asked this question as well in the past and have never
received an answer.
> - are there any plans to fix it?
FWIW, here is a patch, that should fix the issue. The
Digester instance in KnownHost is used in a global way
and needed quite some synchronization. I changed it to
a new instance every time the digester is retrieved,
making the synchronization as a whole unnecessary.
Cheers, Lothar
--------------- snip
### Eclipse Workspace Patch 1.0
#P JSCH_EBD
Index: src/main/java/com/jcraft/jsch/KnownHosts.java
===================================================================
--- src/main/java/com/jcraft/jsch/KnownHosts.java (revision 24760)
+++ src/main/java/com/jcraft/jsch/KnownHosts.java (working copy)
@@ -39,7 +39,7 @@
private String known_hosts=null;
private java.util.Vector pool=null;
- private MAC hmacsha1=null;
+ private Class hmacsha1_class = null;
KnownHosts(JSch jsch){
super();
@@ -482,17 +482,18 @@
return hosts;
}
- private synchronized MAC getHMACSHA1(){
- if(hmacsha1==null){
+ private MAC getHMACSHA1(){
try{
- Class c=Class.forName(jsch.getConfig("hmac-sha1"));
- hmacsha1=(MAC)(c.newInstance());
+ if (hmacsha1_class == null){
+ String hmacsha1_classname = JSch.getConfig("hmac-sha1");
+ hmacsha1_class = Class.forName(hmacsha1_classname);
+ }
+ return (MAC) hmacsha1_class.newInstance();
}
catch(Exception e){
System.err.println("hmacsha1: "+e);
}
- }
- return hmacsha1;
+ return null;
}
HostKey createHashedHostKey(String host, byte[]key) throws JSchException {
@@ -539,14 +540,12 @@
}
MAC macsha1=getHMACSHA1();
try{
- synchronized(macsha1){
macsha1.init(salt);
byte[] foo=Util.str2byte(_host);
macsha1.update(foo, 0, foo.length);
byte[] bar=new byte[macsha1.getBlockSize()];
macsha1.doFinal(bar, 0);
return Util.array_equals(hash, bar);
- }
}
catch(Exception e){
System.out.println(e);
@@ -570,13 +569,11 @@
}
}
try{
- synchronized(macsha1){
macsha1.init(salt);
byte[] foo=Util.str2byte(host);
macsha1.update(foo, 0, foo.length);
hash=new byte[macsha1.getBlockSize()];
macsha1.doFinal(hash, 0);
- }
}
catch(Exception e){
}
--------------- snip
|
|
From: Vladimir K. <vla...@or...> - 2016-02-10 08:38:34
|
Hi, Recently a classical deadlock was found in KnownHosts. It is described in a bug that was filed against NetBeans https://netbeans.org/bugzilla/show_bug.cgi?id=257800 but the reason is obviously in jsch itself. The questions are: - is this problem already known? - are there any plans to fix it? - does jsch accept contributions? if yes, I can try fixing this and propose a patch The below is jsut a copy-paste of some info from the bug: "SFTP" thread - has locked KnownHosts instance - then tries to lock KnownHosts.pool "ConnectionManager queue" thread - has locked KnownHosts.pool - then tries to lock KnownHosts instance Below are minimal thread fgarments that illustrate this (note that there are no NB code in these stacks): "ConnectionManager queue" Id=371 in BLOCKED on lock=com.jcraft.jsch.KnownHosts@24a91105 owned by SFTP: : Uploading /home/kiss/netbeans-8.1/cnd/bin/Linux-x86_64/rfs_controller touser@11.44.33.55 <mailto:user@11.44.33.55>:/var/tmp/dlight_ikiss/6b88f630/tools/Linux-x86_64/rfs_controller Id=388 at com.jcraft.jsch.KnownHosts.getHMACSHA1(KnownHosts.java:486) at com.jcraft.jsch.KnownHosts.access$000(KnownHosts.java:35) at com.jcraft.jsch.KnownHosts$HashedHostKey.isMatched(KnownHosts.java:540) at com.jcraft.jsch.KnownHosts.getHostKey(KnownHosts.java:361) - locked java.util.Vector@79ee48d at com.jcraft.jsch.Session.checkHost(Session.java:809) at com.jcraft.jsch.Session.connect(Session.java:342) "SFTP: : Uploading /home/kiss/netbeans-8.1/cnd/bin/Linux-x86_64/rfs_controller touser@11.44.33.55 <mailto:user@11.44.33.55>:/var/tmp/dlight_ikiss/6b88f630/tools/Linux-x86_64/rfs_controller" Id=388 in BLOCKED on lock=java.util.Vector@79ee48d owned by ConnectionManager queue Id=371 at com.jcraft.jsch.KnownHosts.check(KnownHosts.java:263) at com.jcraft.jsch.Session.checkHost(Session.java:732) - locked com.jcraft.jsch.KnownHosts@24a91105 at com.jcraft.jsch.Session.connect(Session.java:342) Thank you! Vladimir |
|
From: Peter H. <pet...@gm...> - 2016-01-18 17:17:08
|
At the moment it seems JSch isn't very verbose as to what happens AFTER the ssh connection is established. You can configure a logger but it will only give you information on the phase up until the SSH connection is established. Nothing more. Consider the following local port forwarding scenario: myworkstation --> jumphost --> desthost I would like to see the following logged: 1. When myworkstation receives a tcp connection it should log that this is happening, i.e in the Socket.accept(). Something like: "Received connection on myworkstation:lport from 10.1.2.3" 2. Following the above JSch should log what it is now attempting to do. Something like: "Instructing SSH server at jumphost to establish connection to desthost:rport" 3. The result of the previous can be either success or failure. In case of success, JSch should log something like: "Connection successfully established from jumphost to desthost:rport. Local port forwarding is now active" In case of failure something like: "jumphost cannot establish connection to desthost:rport" Is this somehow possible or do I need to file a feature request? Peter |
|
From: Andrew W. <agw...@gm...> - 2016-01-04 22:37:30
|
One the subject is misspelled. Two, this isn't how this stuff works. Please goto the link below, https://lists.sourceforge.net/lists/listinfo/jsch-users And follow the instructions there. On Jan 4, 2016 5:33 PM, "Ulises Vazquez" <uva...@ho...> wrote: > Hi Andrew, > > I'm not sure that I understood. What do you mean with "Please stop"? > > Regards, > > *Ulises Vázquez Rocha * > Oracle Certified Professional DBA > Red Hat Certified Technician > > > > > > ------------------------------ > Date: Mon, 4 Jan 2016 17:22:26 -0500 > Subject: Re: [JSch-users] Unsubscripe > From: agw...@gm... > To: uva...@ho... > CC: jsc...@li...; kam...@gm... > > Please stop. > On Jan 4, 2016 11:35 AM, "Ulises Vazquez" <uva...@ho...> wrote: > > Hi, I also want to unsubscribe from this mailing list. > > Thank you in advance. > > *Ulises Vázquez Rocha * > Oracle Certified Professional DBA > Red Hat Certified Technician > > > > > > ------------------------------ > Date: Mon, 4 Jan 2016 15:19:46 +0800 > From: kam...@gm... > To: JSc...@li... > Subject: [JSch-users] Unsubscripe > > Kindly unsubscribe my email from the list > > -- > Regards, > Kamesh > > > ------------------------------------------------------------------------------ > _______________________________________________ JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users > > > ------------------------------------------------------------------------------ > > _______________________________________________ > JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users > > |
|
From: Ulises V. <uva...@ho...> - 2016-01-04 22:33:01
|
Hi Andrew, I'm not sure that I understood. What do you mean with "Please stop"? Regards, Ulises Vázquez Rocha Oracle Certified Professional DBA Red Hat Certified Technician Date: Mon, 4 Jan 2016 17:22:26 -0500 Subject: Re: [JSch-users] Unsubscripe From: agw...@gm... To: uva...@ho... CC: jsc...@li...; kam...@gm... Please stop. On Jan 4, 2016 11:35 AM, "Ulises Vazquez" <uva...@ho...> wrote: Hi, I also want to unsubscribe from this mailing list. Thank you in advance. Ulises Vázquez Rocha Oracle Certified Professional DBA Red Hat Certified Technician Date: Mon, 4 Jan 2016 15:19:46 +0800 From: kam...@gm... To: JSc...@li... Subject: [JSch-users] Unsubscripe Kindly unsubscribe my email from the list -- Regards, Kamesh ------------------------------------------------------------------------------ _______________________________________________ JSch-users mailing list JSc...@li... https://lists.sourceforge.net/lists/listinfo/jsch-users ------------------------------------------------------------------------------ _______________________________________________ JSch-users mailing list JSc...@li... https://lists.sourceforge.net/lists/listinfo/jsch-users |
|
From: Andrew W. <agw...@gm...> - 2016-01-04 22:22:33
|
Please stop. On Jan 4, 2016 11:35 AM, "Ulises Vazquez" <uva...@ho...> wrote: > Hi, I also want to unsubscribe from this mailing list. > > Thank you in advance. > > *Ulises Vázquez Rocha * > Oracle Certified Professional DBA > Red Hat Certified Technician > > > > > > ------------------------------ > Date: Mon, 4 Jan 2016 15:19:46 +0800 > From: kam...@gm... > To: JSc...@li... > Subject: [JSch-users] Unsubscripe > > Kindly unsubscribe my email from the list > > -- > Regards, > Kamesh > > > ------------------------------------------------------------------------------ > _______________________________________________ JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users > > > ------------------------------------------------------------------------------ > > _______________________________________________ > JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users > > |
|
From: Ulises V. <uva...@ho...> - 2016-01-04 16:32:27
|
Hi, I also want to unsubscribe from this mailing list. Thank you in advance. Ulises Vázquez Rocha Oracle Certified Professional DBA Red Hat Certified Technician Date: Mon, 4 Jan 2016 15:19:46 +0800 From: kam...@gm... To: JSc...@li... Subject: [JSch-users] Unsubscripe Kindly unsubscribe my email from the list -- Regards, Kamesh ------------------------------------------------------------------------------ _______________________________________________ JSch-users mailing list JSc...@li... https://lists.sourceforge.net/lists/listinfo/jsch-users |
|
From: Kamesh c <kam...@gm...> - 2016-01-04 07:19:53
|
Kindly unsubscribe my email from the list -- Regards, Kamesh |
|
From: vikas b. <vik...@gm...> - 2015-12-30 09:56:34
|
Your command will run on shell/terminal. So you need to take shell first
the run your command
String[] cmd = {"/bin/sh",
"-c",
"ssh -t -o ProxyCommand ssh fox@10.0.0.1 nc %h %p
22 ubuntu@10.0.0.22 ls -l"};
On Tue, Dec 22, 2015 at 9:14 PM, Mohamed Boussaa <moh...@gm...>
wrote:
> I am running this command on my mac terminal :
>
> ssh -t -o "ProxyCommand ssh fox@10.0.0.1 nc %h %p 22" ubuntu@10.0.0.22
> "ls -l"
>
> It works. But when I run it like below in eclipse:
>
> List<String> result = new ArrayList<String>();
>
> java.lang.Process pp;
>
> try {
>
> pp = Runtime.getRuntime().exec("ssh -t -o ProxyCommand ssh
> fox@10.0.0.1 nc %h %p 22 ubuntu@10.0.0.22 ls -l");
>
> pp.waitFor();
>
> BufferedReader br = new BufferedReader(new
> InputStreamReader(pp.getInputStream()));
>
> String line = "";
>
> while ((line = br.readLine()) != null) {
>
> System.out.println("line :"+line);
>
> result.add(line);
>
> }
>
> } catch (IOException e) {
>
> e.printStackTrace();
>
> } catch (InterruptedException e) {
>
> e.printStackTrace();
>
> }
>
>
> It doest not work and does not print any thing on the console.
>
> Do you have an idea ?
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> JSch-users mailing list
> JSc...@li...
> https://lists.sourceforge.net/lists/listinfo/jsch-users
>
|
|
From: Mohamed B. <moh...@gm...> - 2015-12-22 15:44:10
|
I am running this command on my mac terminal :
ssh -t -o "ProxyCommand ssh fox@10.0.0.1 nc %h %p 22" ubuntu@10.0.0.22 "ls -l"
It works. But when I run it like below in eclipse:
List<String> result = new ArrayList<String>();
java.lang.Process pp;
try {
pp = Runtime.getRuntime().exec("ssh -t -o ProxyCommand ssh
fox@10.0.0.1 nc %h %p 22 ubuntu@10.0.0.22 ls -l");
pp.waitFor();
BufferedReader br = new BufferedReader(new
InputStreamReader(pp.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
System.out.println("line :"+line);
result.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
It doest not work and does not print any thing on the console.
Do you have an idea ?
|
|
From: Mohamed B. <moh...@gm...> - 2015-12-18 16:35:18
|
can you give me an example according to my settings? |
|
From: Hajo P. <haj...@fo...> - 2015-12-18 16:02:14
|
Am Fri, 18 Dec 2015 16:46:45 +0100
schrieb Mohamed Boussaa <moh...@gm...>:
> I did that but I got "connection refused"
>
>
>
> StringBuilder outputBuffer = new StringBuilder();
>
>
> String host="10.0.0.1"; // First level target
>
> String user="user1";
>
> String password="pass1";
>
> String tunnelRemoteHost="10.0.0.22"; // The host of the
> second target
>
> String secondPassword="pass2";
>
> int port=22;
>
>
>
> JSch jsch=new JSch();
>
> Session session=jsch.getSession(user, host, port);
>
> session.setPassword(password);
>
> localUserInfo lui=new localUserInfo();
>
> session.setUserInfo(lui);
>
> session.setConfig("StrictHostKeyChecking", "no");
>
> // create port from 2233 on local system to port 22 on
> tunnelRemoteHost
>
> session.setPortForwardingL(2251, tunnelRemoteHost, 22);
>
> session.connect();
>
> session.openChannel("direct-tcpip");
>
>
> // create a session connected to port 2233 on the local host.
>
> Session secondSession = jsch.getSession("user2",
> tunnelRemoteHost, 2251);
I didn't test or compile anything, but I think this line is wrong.
You opened up your tunnel port on the FIRST host. So you have to
connect to your first host (ip 10.0.0.1 - called "host" in your code)
to reach the second one by tunnel.
regards
Hajo
>
> secondSession.setPassword(secondPassword);
>
> secondSession.setUserInfo(lui);
>
> secondSession.setConfig("StrictHostKeyChecking", "no");
>
>
> secondSession.connect(); // now we're connected to the
> secondary system
>
> Channel channel=secondSession.openChannel("exec");
>
> ((ChannelExec)channel).setCommand("hostname");
>
>
> channel.setInputStream(null);
>
>
> InputStream stdout=channel.getInputStream();
>
>
> channel.connect();
>
> ------------------------------------------------------------------------------
> _______________________________________________
> JSch-users mailing list
> JSc...@li...
> https://lists.sourceforge.net/lists/listinfo/jsch-users
|
|
From: Mohamed B. <moh...@gm...> - 2015-12-18 15:46:51
|
I did that but I got "connection refused"
StringBuilder outputBuffer = new StringBuilder();
String host="10.0.0.1"; // First level target
String user="user1";
String password="pass1";
String tunnelRemoteHost="10.0.0.22"; // The host of the second target
String secondPassword="pass2";
int port=22;
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, port);
session.setPassword(password);
localUserInfo lui=new localUserInfo();
session.setUserInfo(lui);
session.setConfig("StrictHostKeyChecking", "no");
// create port from 2233 on local system to port 22 on tunnelRemoteHost
session.setPortForwardingL(2251, tunnelRemoteHost, 22);
session.connect();
session.openChannel("direct-tcpip");
// create a session connected to port 2233 on the local host.
Session secondSession = jsch.getSession("user2",
tunnelRemoteHost, 2251);
secondSession.setPassword(secondPassword);
secondSession.setUserInfo(lui);
secondSession.setConfig("StrictHostKeyChecking", "no");
secondSession.connect(); // now we're connected to the secondary system
Channel channel=secondSession.openChannel("exec");
((ChannelExec)channel).setCommand("hostname");
channel.setInputStream(null);
InputStream stdout=channel.getInputStream();
channel.connect();
|
|
From: Bogdan S. <bog...@gm...> - 2015-12-18 15:27:28
|
On Fri, Dec 18, 2015 at 5:06 PM, Mohamed Boussaa <moh...@gm...> wrote: > 2015-12-18 15:56 GMT+01:00 Shai Ayal <sh...@gm...>: > > Maybe use port forwarding ? > > How? > http://www.jcraft.com/jsch/examples/PortForwardingR.java.html + http://www.jcraft.com/jsch/examples/PortForwardingL.java.html |
|
From: Mohamed B. <moh...@gm...> - 2015-12-18 15:07:00
|
2015-12-18 15:56 GMT+01:00 Shai Ayal <sh...@gm...>: > Maybe use port forwarding ? How? |
|
From: Shai A. <sh...@gm...> - 2015-12-18 14:56:55
|
Maybe use port forwarding ?
On יום ו׳, 18 בדצמ׳ 2015 at 16:23 Mohamed Boussaa <moh...@gm...>
wrote:
> I am trying to connect in Java to my machines in the cloud using JSCH.
>
> My machine's IP is 10.0.0.1.
>
> In this host machine I want to connect to a nested machine with IP
> 10.0.0.22.
>
> Actually I am connecting to the 10.0.0.1 machine using the following code:
>
> private static String user = "ubuntu";
> private static String host = "10.0.0.1";
> private static String password = "mypass";
> private static String command = "ls";
>
> public static void main(String args[]) throws JSchException,
> InterruptedException
> {
> JSch jsch = new JSch();
> Session session = jsch.getSession(user, host, 22);
> session.setPassword(password);
> session.setConfig("StrictHostKeyChecking", "no");
> session.connect(10*1000);
> Channel channel = session.openChannel("shell");
> InputStream is = new ByteArrayInputStream(command.getBytes());
> channel.setInputStream(is);
> channel.setOutputStream(System.out);
> channel.connect(15 * 1000);
> Thread.sleep(3*1000);
>
>
> channel.disconnect();
> session.disconnect();
> }
>
> My question is how could I open a new connection to the machine
> 10.0.0.22 inside the 10.0.0.1's machine using JSCH API?
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> JSch-users mailing list
> JSc...@li...
> https://lists.sourceforge.net/lists/listinfo/jsch-users
>
|
|
From: Mohamed B. <moh...@gm...> - 2015-12-18 14:22:23
|
I am trying to connect in Java to my machines in the cloud using JSCH.
My machine's IP is 10.0.0.1.
In this host machine I want to connect to a nested machine with IP 10.0.0.22.
Actually I am connecting to the 10.0.0.1 machine using the following code:
private static String user = "ubuntu";
private static String host = "10.0.0.1";
private static String password = "mypass";
private static String command = "ls";
public static void main(String args[]) throws JSchException,
InterruptedException
{
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect(10*1000);
Channel channel = session.openChannel("shell");
InputStream is = new ByteArrayInputStream(command.getBytes());
channel.setInputStream(is);
channel.setOutputStream(System.out);
channel.connect(15 * 1000);
Thread.sleep(3*1000);
channel.disconnect();
session.disconnect();
}
My question is how could I open a new connection to the machine
10.0.0.22 inside the 10.0.0.1's machine using JSCH API?
|
|
From: Atsuhiko Y. <ym...@jc...> - 2015-11-19 16:09:51
|
Hi,
On Tue, Nov 10, 2015 at 6:23 PM, Reynir Björnsson
<rey...@gm...> wrote:
> Does JSch support OpenSSH style certificates[1]?
> In particular for host keys when connecting as a client.
It has not been supported yet.
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
+1-415-578-3454
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
|
|
From: Hajo P. <haj...@fo...> - 2015-11-17 10:33:20
|
Hello Reynir, have a look at http://stackoverflow.com/questions/24488162/jcraft-scp-using-private-key-without-password/24488776#24488776. You will find examples of connection building with and without host key. regards, Hajo Am 10.11.2015 um 10:23 schrieb Reynir Björnsson: > Hello, > > Does JSch support OpenSSH style certificates[1]? In particular for > host keys when connecting as a client. > > > Regards, > > Reynir > > [1]: See the CERTIFICATES section of ssh-keygen(1) > > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users -- *Hajo Passon* Softwarearchitekt form4 GmbH & Co. KG Schlesische Straße 26 10997 Berlin Telefon: (030) 278784-14 Fax: (030) 278784-10 E-Mail: haj...@fo... Website: www.form4.de Geschäftsführung: Oliver Meimberg AG Charlottenburg, HRA 31947 USt-ID: DE 212945315 |
|
From: Lothar K. <jo...@ki...> - 2015-11-17 09:31:27
|
Am 10.11.2015 um 10:23 schrieb Reynir Björnsson: > Does JSch support OpenSSH style certificates[1]? In particular > for host keys when connecting as a client. AFAIK the OpenSSH-format is essentially the format being used within SSH itself, so the short answer should be yes. What exactly do you want to do. There are helper-methods e.g. KeyPair.load to load a KeyPair from the two files. Cheers, Lothar |
|
From: Reynir B. <rey...@gm...> - 2015-11-10 09:23:36
|
Hello, Does JSch support OpenSSH style certificates[1]? In particular for host keys when connecting as a client. Regards, Reynir [1]: See the CERTIFICATES section of ssh-keygen(1) |
|
From: Kagoshima D. A. Co., L. T.O. <ooh...@da...> - 2015-11-06 09:15:34
|
Hello. Did a phenomenon reappear in the test class which I provided? |
|
From: Kagoshima D. A. Co., L. T.O. <ooh...@da...> - 2015-10-26 02:49:56
|
Hello.
> can you provide a test class reduced to the code that helps
> reproducing the effect?
We will be able to provide it.
+++++<Sftp.java>+++++++++++++++++++++++++++++++
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/**
* This program will demonstrate the sftp protocol support.
* $ CLASSPATH=.:../build javac Sftp.java
* $ CLASSPATH=.:../build java Sftp
* You will be asked username, host and passwd.
* If everything works fine, you will get a prompt 'sftp>'.
* 'help' command will show available command.
* In current implementation, the destination path for 'get' and 'put'
* commands must be a file, not a directory.
*
*/
import com.jcraft.jsch.*;
import java.awt.*;
import javax.swing.*;
public class Sftp{
public static void main(String[] arg){
try{
JSch jsch=new JSch();
// test code add ->
// NG
JSch.setConfig("mac.c2s", "hmac-sha2-256");
JSch.setConfig("mac.s2c", "hmac-sha2-256");
// OK
//JSch.setConfig("mac.c2s", "hmac-sha1");
//JSch.setConfig("mac.s2c", "hmac-sha1");
// test code add <-
String host=null;
if(arg.length>0){
host=arg[0];
}
else{
host=JOptionPane.showInputDialog("Enter username@hostname",
System.getProperty("user.name")+
"@localhost");
}
String user=host.substring(0, host.indexOf('@'));
host=host.substring(host.indexOf('@')+1);
int port=22;
Session session=jsch.getSession(user, host, port);
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
java.io.InputStream in=System.in;
java.io.PrintStream out=System.out;
java.util.Vector cmds=new java.util.Vector();
byte[] buf=new byte[1024];
int i;
String str;
int level=0;
while(true){
out.print("sftp> ");
cmds.removeAllElements();
i=in.read(buf, 0, 1024);
if(i<=0)break;
i--;
if(i>0 && buf[i-1]==0x0d)i--;
//str=new String(buf, 0, i);
//System.out.println("|"+str+"|");
int s=0;
for(int ii=0; ii<i; ii++){
if(buf[ii]==' '){
if(ii-s>0){ cmds.addElement(new String(buf, s, ii-s)); }
while(ii<i){if(buf[ii]!=' ')break; ii++;}
s=ii;
}
}
if(s<i){ cmds.addElement(new String(buf, s, i-s)); }
if(cmds.size()==0)continue;
String cmd=(String)cmds.elementAt(0);
if(cmd.equals("quit")){
c.quit();
break;
}
if(cmd.equals("exit")){
c.exit();
break;
}
if(cmd.equals("rekey")){
session.rekey();
continue;
}
if(cmd.equals("compression")){
if(cmds.size()<2){
out.println("compression level: "+level);
continue;
}
try{
level=Integer.parseInt((String)cmds.elementAt(1));
if(level==0){
session.setConfig("compression.s2c", "none");
session.setConfig("compression.c2s", "none");
}
else{
session.setConfig("compression.s2c", "zl...@op...,zlib,none");
session.setConfig("compression.c2s", "zl...@op...,zlib,none");
}
}
catch(Exception e){}
session.rekey();
continue;
}
if(cmd.equals("cd") || cmd.equals("lcd")){
if(cmds.size()<2) continue;
String path=(String)cmds.elementAt(1);
try{
if(cmd.equals("cd")) c.cd(path);
else c.lcd(path);
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("rm") || cmd.equals("rmdir") || cmd.equals("mkdir")){
if(cmds.size()<2) continue;
String path=(String)cmds.elementAt(1);
try{
if(cmd.equals("rm")) c.rm(path);
else if(cmd.equals("rmdir")) c.rmdir(path);
else c.mkdir(path);
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("chgrp") || cmd.equals("chown") || cmd.equals("chmod")){
if(cmds.size()!=3) continue;
String path=(String)cmds.elementAt(2);
int foo=0;
if(cmd.equals("chmod")){
byte[] bar=((String)cmds.elementAt(1)).getBytes();
int k;
for(int j=0; j<bar.length; j++){
k=bar[j];
if(k<'0'||k>'7'){foo=-1; break;}
foo<<=3;
foo|=(k-'0');
}
if(foo==-1)continue;
}
else{
try{foo=Integer.parseInt((String)cmds.elementAt(1));}
catch(Exception e){continue;}
}
try{
if(cmd.equals("chgrp")){ c.chgrp(foo, path); }
else if(cmd.equals("chown")){ c.chown(foo, path); }
else if(cmd.equals("chmod")){ c.chmod(foo, path); }
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("pwd") || cmd.equals("lpwd")){
str=(cmd.equals("pwd")?"Remote":"Local");
str+=" working directory: ";
if(cmd.equals("pwd")) str+=c.pwd();
else str+=c.lpwd();
out.println(str);
continue;
}
if(cmd.equals("ls") || cmd.equals("dir")){
String path=".";
if(cmds.size()==2) path=(String)cmds.elementAt(1);
try{
java.util.Vector vv=c.ls(path);
if(vv!=null){
for(int ii=0; ii<vv.size(); ii++){
// out.println(vv.elementAt(ii).toString());
Object obj=vv.elementAt(ii);
if(obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry){
out.println(((com.jcraft.jsch.ChannelSftp.LsEntry)obj).getLongname());
}
}
}
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("lls") || cmd.equals("ldir")){
String path=".";
if(cmds.size()==2) path=(String)cmds.elementAt(1);
try{
java.io.File file=new java.io.File(path);
if(!file.exists()){
out.println(path+": No such file or directory");
continue;
}
if(file.isDirectory()){
String[] list=file.list();
for(int ii=0; ii<list.length; ii++){
out.println(list[ii]);
}
continue;
}
out.println(path);
}
catch(Exception e){
System.out.println(e);
}
continue;
}
if(cmd.equals("get") ||
cmd.equals("get-resume") || cmd.equals("get-append") ||
cmd.equals("put") ||
cmd.equals("put-resume") || cmd.equals("put-append")
){
if(cmds.size()!=2 && cmds.size()!=3) continue;
String p1=(String)cmds.elementAt(1);
// String p2=p1;
String p2=".";
if(cmds.size()==3)p2=(String)cmds.elementAt(2);
try{
SftpProgressMonitor monitor=new MyProgressMonitor();
if(cmd.startsWith("get")){
int mode=ChannelSftp.OVERWRITE;
if(cmd.equals("get-resume")){ mode=ChannelSftp.RESUME; }
else if(cmd.equals("get-append")){ mode=ChannelSftp.APPEND; }
c.get(p1, p2, monitor, mode);
}
else{
int mode=ChannelSftp.OVERWRITE;
if(cmd.equals("put-resume")){ mode=ChannelSftp.RESUME; }
else if(cmd.equals("put-append")){ mode=ChannelSftp.APPEND; }
c.put(p1, p2, monitor, mode);
}
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("ln") || cmd.equals("symlink") || cmd.equals("rename")){
if(cmds.size()!=3) continue;
String p1=(String)cmds.elementAt(1);
String p2=(String)cmds.elementAt(2);
try{
if(cmd.equals("rename")) c.rename(p1, p2);
else c.symlink(p1, p2);
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("stat") || cmd.equals("lstat")){
if(cmds.size()!=2) continue;
String p1=(String)cmds.elementAt(1);
SftpATTRS attrs=null;
try{
if(cmd.equals("stat")) attrs=c.stat(p1);
else attrs=c.lstat(p1);
}
catch(SftpException e){
System.out.println(e.toString());
}
if(attrs!=null){
out.println(attrs);
}
else{
}
continue;
}
if(cmd.equals("readlink")){
if(cmds.size()!=2) continue;
String p1=(String)cmds.elementAt(1);
String filename=null;
try{
filename=c.readlink(p1);
out.println(filename);
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("realpath")){
if(cmds.size()!=2) continue;
String p1=(String)cmds.elementAt(1);
String filename=null;
try{
filename=c.realpath(p1);
out.println(filename);
}
catch(SftpException e){
System.out.println(e.toString());
}
continue;
}
if(cmd.equals("version")){
out.println("SFTP protocol version "+c.version());
continue;
}
if(cmd.equals("help") || cmd.equals("?")){
out.println(help);
continue;
}
out.println("unimplemented command: "+cmd);
}
session.disconnect();
}
catch(Exception e){
System.out.println(e);
}
System.exit(0);
}
public static class MyUserInfo implements UserInfo, UIKeyboardInteractive{
public String getPassword(){ return passwd; }
public boolean promptYesNo(String str){
Object[] options={ "yes", "no" };
int foo=JOptionPane.showOptionDialog(null,
str,
"Warning",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
return foo==0;
}
String passwd;
JTextField passwordField=(JTextField)new JPasswordField(20);
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return true; }
public boolean promptPassword(String message){
Object[] ob={passwordField};
int result=
JOptionPane.showConfirmDialog(null, ob, message,
JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_OPTION){
passwd=passwordField.getText();
return true;
}
else{ return false; }
}
public void showMessage(String message){
JOptionPane.showMessageDialog(null, message);
}
final GridBagConstraints gbc =
new GridBagConstraints(0,0,1,1,1,1,
GridBagConstraints.NORTHWEST,
GridBagConstraints.NONE,
new Insets(0,0,0,0),0,0);
private Container panel;
public String[] promptKeyboardInteractive(String destination,
String name,
String instruction,
String[] prompt,
boolean[] echo){
panel = new JPanel();
panel.setLayout(new GridBagLayout());
gbc.weightx = 1.0;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridx = 0;
panel.add(new JLabel(instruction), gbc);
gbc.gridy++;
gbc.gridwidth = GridBagConstraints.RELATIVE;
JTextField[] texts=new JTextField[prompt.length];
for(int i=0; i<prompt.length; i++){
gbc.fill = GridBagConstraints.NONE;
gbc.gridx = 0;
gbc.weightx = 1;
panel.add(new JLabel(prompt[i]),gbc);
gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weighty = 1;
if(echo[i]){
texts[i]=new JTextField(20);
}
else{
texts[i]=new JPasswordField(20);
}
panel.add(texts[i], gbc);
gbc.gridy++;
}
if(JOptionPane.showConfirmDialog(null, panel,
destination+": "+name,
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE)
==JOptionPane.OK_OPTION){
String[] response=new String[prompt.length];
for(int i=0; i<prompt.length; i++){
response[i]=texts[i].getText();
}
return response;
}
else{
return null; // cancel
}
}
}
/*
public static class MyProgressMonitor implements com.jcraft.jsch.ProgressMonitor{
JProgressBar progressBar;
JFrame frame;
long count=0;
long max=0;
public void init(String info, long max){
this.max=max;
if(frame==null){
frame=new JFrame();
frame.setSize(200, 20);
progressBar = new JProgressBar();
}
count=0;
frame.setTitle(info);
progressBar.setMaximum((int)max);
progressBar.setMinimum((int)0);
progressBar.setValue((int)count);
progressBar.setStringPainted(true);
JPanel p=new JPanel();
p.add(progressBar);
frame.getContentPane().add(progressBar);
frame.setVisible(true);
System.out.println("!info:"+info+", max="+max+" "+progressBar);
}
public void count(long count){
this.count+=count;
System.out.println("count: "+count);
progressBar.setValue((int)this.count);
}
public void end(){
System.out.println("end");
progressBar.setValue((int)this.max);
frame.setVisible(false);
}
}
*/
public static class MyProgressMonitor implements SftpProgressMonitor{
ProgressMonitor monitor;
long count=0;
long max=0;
public void init(int op, String src, String dest, long max){
this.max=max;
monitor=new ProgressMonitor(null,
((op==SftpProgressMonitor.PUT)?
"put" : "get")+": "+src,
"", 0, (int)max);
count=0;
percent=-1;
monitor.setProgress((int)this.count);
monitor.setMillisToDecideToPopup(1000);
}
private long percent=-1;
public boolean count(long count){
this.count+=count;
if(percent>=this.count*100/max){ return true; }
percent=this.count*100/max;
monitor.setNote("Completed "+this.count+"("+percent+"%) out of "+max+".");
monitor.setProgress((int)this.count);
return !(monitor.isCanceled());
}
public void end(){
monitor.close();
}
}
private static String help =
" Available commands:\n"+
" * means unimplemented command.\n"+
"cd path Change remote directory to 'path'\n"+
"lcd path Change local directory to 'path'\n"+
"chgrp grp path Change group of file 'path' to 'grp'\n"+
"chmod mode path Change permissions of file 'path' to 'mode'\n"+
"chown own path Change owner of file 'path' to 'own'\n"+
"help Display this help text\n"+
"get remote-path [local-path] Download file\n"+
"get-resume remote-path [local-path] Resume to download file.\n"+
"get-append remote-path [local-path] Append remote file to local file\n"+
"*lls [ls-options [path]] Display local directory listing\n"+
"ln oldpath newpath Symlink remote file\n"+
"*lmkdir path Create local directory\n"+
"lpwd Print local working directory\n"+
"ls [path] Display remote directory listing\n"+
"*lumask umask Set local umask to 'umask'\n"+
"mkdir path Create remote directory\n"+
"put local-path [remote-path] Upload file\n"+
"put-resume local-path [remote-path] Resume to upload file\n"+
"put-append local-path [remote-path] Append local file to remote file.\n"+
"pwd Display remote working directory\n"+
"stat path Display info about path\n"+
"exit Quit sftp\n"+
"quit Quit sftp\n"+
"rename oldpath newpath Rename remote file\n"+
"rmdir path Remove remote directory\n"+
"rm path Delete remote file\n"+
"symlink oldpath newpath Symlink remote file\n"+
"readlink path Check the target of a symbolic link\n"+
"realpath path Canonicalize the path\n"+
"rekey Key re-exchanging\n"+
"compression level Packet compression will be enabled\n"+
"version Show SFTP version\n"+
"? Synonym for help";
}
++++++++++++++++++++++++++++++++++++++++++
It will be reproduced when you add a line of 25 and 26.
// NG
JSch.setConfig("mac.c2s", "hmac-sha2-256");
JSch.setConfig("mac.s2c", "hmac-sha2-256");
Remove the 25 and 26 lines, you can send a normal file when you add the 28 and 29 of the line.
// OK
JSch.setConfig("mac.c2s", "hmac-sha1");
JSch.setConfig("mac.s2c", "hmac-sha1");
|