jsch

JSch: How to ssh into a server using ssh-keys

早过忘川 提交于 2019-12-03 07:42:57
I want to ssh into a server from behind another ssh server. The gateway server requires a username/password and I can do this. I am using a tunnel to get into the next server, but this one requires only an ssh key. I've generated the key through PuTTY, so it exists for my username but I'm not sure how to retrieve it for my Java program. Is it a configuration? i.e. setConfig("userauth.publickey", "com.jcraft.jsch.UserAuthPublicKey") then how do I use this or something else? Documentation seems to be sparse and I appreciate any help. Anything I've tried gives me an error :"Auth fail" when I

Java git client using jgit

守給你的承諾、 提交于 2019-12-03 07:00:20
I am having some difficulties with a git client written in java. I am using the jGit library to connect through ssh on the git server. The problem is that i don't know how to specify the path to the private key and the passphrase for it. I couldn't find any examples in the jGit documentation about what functions i need to call. From what i read the jGit library is using JSch to connect to the server using ssh and JSch supports private keys and passphrases. Does anyone have any experience with this or has some working code? Thank you I didn't ever use jGit, but from looking at the Javadocs

How to use Java JSch library to read remote file line by line?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use Java to read a file line by line, which is very simple (there are multiple solutions for this on stackoverflow.com), but the caveat here is that the file is located on a remote server, and it is not possible to get a local copy (it is a massive collection of millions of Amazon reviews in a single .txt file). JSch comes with two example classes that copy files to and from remote hosts, namely ScpTo and ScpFrom. I am interested in reading the file from the remote host line by line; ScpFrom would try to copy the whole thing

SFTP via JSch is throwing error 4: Failure

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am facing a peculiar issue while trying to SFTP a file from Windows to Unix server. The error "stack trace" is - 4: Failure at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:2459) at com.jcraft.jsch.ChannelSftp._sendCLOSE(ChannelSftp.java:2465) at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:683) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:475) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:365) I have searched a lot on other forums but could

How do you set the configuration for jschconfigsessionfactory for jgit so that pull and push work?

落爺英雄遲暮 提交于 2019-12-03 03:01:45
I am trying to do a git pull/push using jgit's api with the following code org.eclipse.jgit.api.Git.open(theRepoFile).pull().call() but I am getting exceptions JSchException Auth fail com.jcraft.jsch.Session.connect (Session.java:461) org.eclipse.jgit.transport.JschConfigSessionFactory.getSession (JschConfigSessionFactory.java:116) org.eclipse.jgit.transport.SshTransport.getSession (SshTransport.java:121) org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init> (TransportGitSsh.java:306) org.eclipse.jgit.transport.TransportGitSsh.openPush (TransportGitSsh.java:152) org.eclipse.jgit

Retrieving data from an SFTP server using JSch

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using JSch for retrieving a file from a remote machine by SFTP. Here is the code public class TestSFTPinJava { public static void main(String args[]) { JSch jsch = new JSch(); Session session = null; try { session = jsch.getSession("username", "sftp.abc.com", 22); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword("password"); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; System.out.println("Directory:" + sftpChannel.pwd());

scp via java

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the best method of performing an scp transfer via the Java programming language? It seems I may be able to perform this via JSSE, JSch or the bouncy castle java libraries. None of these solutions seem to have an easy answer. 回答1: I ended up using Jsch - it was pretty straightforward, and seemed to scale up pretty well (I was grabbing a few thousand files every few minutes). 回答2: plug: sshj is the only sane choice! See these examples to get started: download , upload . 回答3: Take a look here That is the source code for Ants' SCP task.

JSCH sudo su command “tty” error

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Java - Jsch sudo command. I am using Jsch and my task is to login to server and run command as following sudo su - bumboo Using following code i am successfully able to connect but when i try to run command it gives me error sudo: sorry, you must have a tty to run sudo Following is my code public static Channel sudoBamboo(Session session, String sudo_pass) throws Exception { ChannelExec channel = (ChannelExec) session.openChannel("exec"); //SUDO to bamboo user String command = "sudo su - bumboo"; channel.setCommand(command); //InputStream in

Use JSch sudo example and Channel.setPty for running sudo command on remote host

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have used JSch Sudo example under following link: http://www.jcraft.com/jsch/examples/Sudo.java.html And changed it a bit and get rid of all the dialogs as I have to use it for EC2 instances using PuTTY. Now my code looks like this: import com.jcraft.jsch.*; import java.awt.*; import javax.swing.*; import java.io.*; public class sudo{ public static void main(String[] arg){ try{ JSch jsch=new JSch(); String host=null; if(arg.length>0){ host=arg[0]; } String privateKey = "my private key.pem"; jsch.addIdentity(privateKey, ""); Session session

JSch getting “invalid privatekey:” while trying to load an RSA private key by KeyPairGenerator

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using java.security.KeyPairGenerator to gen an RSA key pair, and then try to load the private key via the KeyPair class provided in Jsch(0.1.49). The code: public static void main(String[] args) { String header = "-----BEGIN RSA PRIVATE KEY-----"; String footer = "-----END RSA PRIVATE KEY-----"; KeyPairGenerator keyPairGenerator; try { keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048, new SecureRandom()); PrivateKey privateKey = keyPairGenerator.genKeyPair().getPrivate(); String key = new String