jsch

Can we use JSch for SSH key-based communication?

怎甘沉沦 提交于 2019-11-26 15:51:05
I am using JSch for sftp communication, now i want to use facilitate the key-based authentication, key is loaded on client and server machine once by my network team and all later communication would be only user based for which we have loaded the key. sftp -oPort=10022 jmark@192.18.0.246 as tjill@192.18.0.135 like this command work fine and connect to the sftp, how i can achieve this functionality programmatically. if it is not possible using JSch, please suggest some other library. I came across Apache SSHD . It is possible. Have a look at JSch.addIdentity(...) This allows you to use key

Providing input/subcommands to command executed over SSH with JSch

末鹿安然 提交于 2019-11-26 15:33:12
I'm trying to manage router via Java application using Jcraft Jsch library. I'm trying to send Router Config via TFTP server. The problem is in my Java code because this works with PuTTY. This my Java code: int port=22; String name ="R1"; String ip ="192.168.18.100"; String password ="root"; JSch jsch = new JSch(); Session session = jsch.getSession(name, ip, port); session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); System.out.println("Establishing Connection..."); session.connect(); System.out.println("Connection established."); ChannelExec channelExec =

Execute a list of commands from an ArrayList using JSch exec in Java

偶尔善良 提交于 2019-11-26 14:49:22
问题 Using JSch "exec" channel, I connect to a remote server and execute a command. What I can't do is to execute a list of commands stored in ArrayList . I use for loop to pass each element to .setCommand(elem); but for some odd reason, only the last command gets executed. ArrayList<String> lists = new ArrayList<String>(); lists.add("hostname"); lists.add("df -l"); Channel channel=session.openChannel("exec"); for (String elem : lists){ ((ChannelExec)channel).setCommand(elem); } Full Code public

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

﹥>﹥吖頭↗ 提交于 2019-11-26 14:26:19
问题 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 Algorithm negotiation fail

孤者浪人 提交于 2019-11-26 13:50:40
I try to connect SFTP server by Java. I got an error. com.jcraft.jsch.JSchException: Algorithm negotiation fail Here is the POM: <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.53</version> </dependency> Here is the log: INFO: Connecting to **"FTP ADRESS"** port 22 INFO: Connection established INFO: Remote version string: SSH-2.0-Maverick_SSHD INFO: Local version string: SSH-2.0-JSCH-0.1.53 INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 INFO: aes256-ctr is not available. INFO:

“Invalid privatekey” when using JSch

眉间皱痕 提交于 2019-11-26 12:40:30
问题 I\'m using the following code to work with Git in a Java application. I have a valid key (use it all the time), and this specific code has work for me before with the same key and git repository, but now I get the following exception: invalid privatekey: [B@59c40796. At this line: jSch.addIdentity(\"<key_path>/private_key.pem\"); My full code: String remoteURL = \"ssh://git@<git_repository>\"; TransportConfigCallback transportConfigCallback = new SshTransportConfigCallback(); File gitFolder =

SFTP file transfer using Java JSch

雨燕双飞 提交于 2019-11-26 12:12:06
问题 Here is my code, which retrieves content of the file, on the remote server and display as output. package sshexample; import com.jcraft.jsch.*; import java.io.*; public class SSHexample { public static void main(String[] args) { String user = \"user\"; String password = \"password\"; String host = \"192.168.100.103\"; int port=22; String remoteFile=\"sample.txt\"; try { JSch jsch = new JSch(); Session session = jsch.getSession(user, host, port); session.setPassword(password); session

JSch Logs in files

混江龙づ霸主 提交于 2019-11-26 11:56:14
I want to save JSch logs in file because it does not show anything in the console. This is my code: public boolean openConnection() throws ItsSshException { boolean connectSuccess = false; JSch.setLogger(new MyLogger()); Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); jschSSH.setConfig(config); try { sshSession = jschSSH.getSession(username, hostname, port); sshSession.setPassword(password); sshSession.connect(connectionTimeout); LOGGER.info("Connection timeout : " + connectionTimeout); Thread.sleep(1000); sshHChannel = sshSession.openChannel("shell");

com.jcraft.jsch.JSchException: UnknownHostKey

给你一囗甜甜゛ 提交于 2019-11-26 11:39:06
I'm trying to use Jsch to establish an SSH connection in Java. My code produces the following exception: com.jcraft.jsch.JSchException: UnknownHostKey: mywebsite.com. RSA key fingerprint is 22:fb:ee:fe:18:cd:aa:9a:9c:78:89:9f:b4:78:75:b4 I cannot find how to verify the host key in the Jsch documentation. I have included my code below. import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; public class ssh { public static void main(String[] arg) { try { JSch jsch = new JSch(); //create SSH connection String host = "mywebsite.com"; String user = "username"; String password = "123456";

Run a command over SSH with JSch

ぐ巨炮叔叔 提交于 2019-11-26 11:37:19
I'm trying to run a command over SSH with JSch, but JSch has virtually no documentation and the examples I've found are terrible. For example, this one doesn't show code for handling the output stream. And, this one uses an ugly hack to know when to stop reading from the output stream. The following code example written in Java will allow you to execute any command on a foreign computer through SSH from within a java program. You will need to include the com.jcraft.jsch jar file. /* * SSHManager * * @author cabbott * @version 1.0 */ package cabbott.net; import com.jcraft.jsch.*; import java.io