jsch

How to SSH to a server behind another SSH server using JSch?

戏子无情 提交于 2019-12-17 18:44:31
问题 I need to be able to ssh from a Java program into a remote server, and from there SSH to another server. I have credentials for both servers on my client. The commands will be passed automatically from within the app as regular strings (no user input). I need to be able to run those custom commands on the second server and be able to decide what commands to issue during runtime, based on the output and some simple logic. Can I use JSch to do that and if yes, where should I start look into?

Commands executed using JSch behaves differently than in SSH terminal (bypasses confirm prompt message of “yes/”no")

左心房为你撑大大i 提交于 2019-12-17 16:53:43
问题 Note: I log into a device, not a computer, so I login to configuration mode (instead of non configuration mode). I am using JSch library in Java, to login with an SSH protocol. I login like this: channel = con.openChannel("shell"); channel.connect(); In some cases, when I send through the shell a command that needs su (configuration mode) permissions (change configuration), this code bypasses the prompt confirmation message of - this may prevent other users from changing configuration. While

Using JSch to SFTP when one must also switch user

五迷三道 提交于 2019-12-17 09:59:08
问题 I am using JSch in a Java client to connect to a remote server and get some files using SFTP. The following code has been working fine for me: - JSch ssh = new JSch(); JSch.setConfig(FileTransferConstants.STRICT_HOST_KEY_CHECKING, FileTransferConstants.NO); Session session = ssh.getSession(userName, host, port); session.setPassword(password); session.connect(); Channel channel = session.openChannel(FileTransferConstants.SFTP); channel.connect(); ChannelSftp sftp = (ChannelSftp) channel; sftp

JSch SFTP security with session.setConfig(“StrictHostKeyChecking”, “no”);

柔情痞子 提交于 2019-12-17 09:57:49
问题 I use JSch with private key to FTP file jsch.addIdentity(privatekeyfile); Session session = jsch.getSession( "user", "domain.com" ,22); session.setConfig("StrictHostKeyChecking", "no"); Line 3 is in question. Without this line, JSch does not work. My question is: Will line 3 make SFTP transfer insecure? 回答1: Disabling the StrictHostKeyChecking option will make the connection less secure than having the option enabled, because it will let you connect to remote servers without verifying their

How to read JSch command output?

巧了我就是萌 提交于 2019-12-17 09:31:56
问题 I have the following code: JSch jsch = new JSch(); jsch.setKnownHosts(dotSshDir + "/known_hosts"); jsch.addIdentity(dotSshDir + "/id_rsa"); Session session = jsch.getSession(userName, hostname, 22); session.connect(); ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(command); channel.setInputStream(null); channel.setErrStream(System.err); Reader reader = new InputStreamReader(channel.getInputStream()); char[] buf = new char[1024]; int numRead; while (

Simple SSH connect with JSch

南楼画角 提交于 2019-12-17 08:59:42
问题 I am trying to make something from this simple example : SSH, execute remote commands with Android I just want to see if I can connect from my android phone to a linux server using SSH but it doesn't work... Here is my main code : package com.example.ssh; import java.util.Properties; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle

Never ending of reading server response using jSch

牧云@^-^@ 提交于 2019-12-17 06:49:36
问题 I am trying to run commands at unix server by connecting through jSch0.1.49 library. I have gone through the samples provided by jSch and even http://sourceforge.net/apps/mediawiki/jsch/index.php?title=Official_examples I am able to read the response from the server and printed it to console but the loop is * never endin *g. I doubt why the Channele is not closing once it is finished reading response from server. while (true) { while (inputStream.available() > 0) { int i = inputStream.read

How do I run SSH commands on remote system using Java?

試著忘記壹切 提交于 2019-12-17 05:50:14
问题 I am new to this kind of Java application and looking for some sample code on how to connect to a remote server using SSH , execute commands, and get output back using Java as programming language. 回答1: Have a look at Runtime.exec() Javadoc Process p = Runtime.getRuntime().exec("ssh myhost"); PrintStream out = new PrintStream(p.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); out.println("ls -l /home/me"); while (in.ready()) { String s =

Connect to remote MySQL database through SSH using Java

…衆ロ難τιáo~ 提交于 2019-12-17 03:25:07
问题 How can I connect to remote MySQL database through SSH from java application? Small code example is helpful for me and I'd appreciate this. 回答1: My understanding is that you want to access a mysql server running on a remote machine and listening on let's say port 3306 through a SSH tunnel. To create such a tunnel from port 1234 on your local machine to port 3306 on a remote machine using the command line ssh client, you would type the following command from your local machine: ssh -L 1234

Can we use JSch for SSH key-based communication?

心已入冬 提交于 2019-12-17 02:42:19
问题 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