Discussion:
[JSch-users] SSH key forwading
Sachith Withana
2014-03-10 14:53:54 UTC
Permalink
Hi all,

Does JSCH support SSH key forwarding capability?

Problem would be to copy a file from one server to another using my public
key.

I did it using the terminal. I'm wondering how to implement that through
jCraft.

Any help is appreciated!
--
Thanks,
Sachith Withana
Atsuhiko Yamanaka
2014-03-10 23:49:58 UTC
Permalink
Hi,

+-From: Sachith Withana <***@gmail.com> --
|_Date: Mon, 10 Mar 2014 10:53:54 -0400 ________
|
|Does JSCH support SSH key forwarding capability?

Yes, it does.

JSch jsch = new JSch();
jsch.addIdentity("/home/foo/.ssh/id_rsa"
// , "passphrase"
);
...
Channel channel=session.openChannel("shell");
((ChannelShell)channel).setAgentForwarding(true);
...
channel.connect();

By using jsch-agent-proxy[1], you don't have to handle
the private-key file by yourself. You can use ssh-agent or Pageant as you
have done usually on the terminal. Refer to its example[2].

[1] http://www.jcraft.com/jsch-agent-proxy/
[2] https://github.com/ymnk/jsch-agent-proxy/blob/master/examples/src/main/java/com/jcraft/jsch/agentproxy/examples/JSchWithAgentProxy.java


Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
Sachith Withana
2014-03-11 02:46:50 UTC
Permalink
Thanks a lot Atsuhiko.

I tested it out. it works well! :)
Post by Atsuhiko Yamanaka
Hi,
|_Date: Mon, 10 Mar 2014 10:53:54 -0400 ________
|
|Does JSCH support SSH key forwarding capability?
Yes, it does.
JSch jsch = new JSch();
jsch.addIdentity("/home/foo/.ssh/id_rsa"
// , "passphrase"
);
...
Channel channel=session.openChannel("shell");
((ChannelShell)channel).setAgentForwarding(true);
...
channel.connect();
By using jsch-agent-proxy[1], you don't have to handle
the private-key file by yourself. You can use ssh-agent or Pageant as you
have done usually on the terminal. Refer to its example[2].
[1] http://www.jcraft.com/jsch-agent-proxy/
[2]
https://github.com/ymnk/jsch-agent-proxy/blob/master/examples/src/main/java/com/jcraft/jsch/agentproxy/examples/JSchWithAgentProxy.java
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
--
Thanks,
Sachith Withana
Loading...