jsch

Executing multiple bash commands using a Java JSch program after sudo login

余生长醉 提交于 2019-12-29 08:19:15
问题 I am trying to execute multiple bash commands through a Java program which connects to a SSH using JSch. But after sudo login, I am unable to execute any bash commands. From what I have read, after sudo login, we enter into a sub-shell. I wish to use a single channel. I am clueless as to what to do next. ChannelExec chnlex=(ChannelExec) session.openChannel("exec"); InputStream in = chnlex.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(in)); chnlex.setCommand(

Log stdout and stderr from ssh command in the same order it was created

徘徊边缘 提交于 2019-12-29 07:22:07
问题 Short Version: Is it possible to log the stdout and stderr on the local side of a command executed remotely via ssh in the same order as it was output on the remote host? If so, how? Long Version: I am attempting to log the standard and error output from a remotely exec'd SSH command (using Jsch) in the same order as it was output by the remote command. In other words, if the remote command writes "a" to stdout, then "b" to stderr, then "c" to stdout, I want the log on the client (local) side

Java: InvalidAlgorithmParameterException Prime size must be multiple of 64

拟墨画扇 提交于 2019-12-28 18:02:51
问题 I implemented a Java program that will connect and execute a command in a remote server using JSCH. The problem is that whenever I tried to connect to the server, I got the following exception: com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 256 to 2048 (inclusive) I tried the solution of adding the Bouncy Castle provider in jre/lib and security.provider and it works. But I need to

Java JSch changing user on remote machine and execute command

给你一囗甜甜゛ 提交于 2019-12-28 04:28:23
问题 I'm trying to connect to a host, then change the user using "su - john" and then execute a command as john. Is it possible with using only JSch? The problem is that after I create a session and open the channel and execute the aforementioned command it should request password, but nothing happens. This is how I connect to the remote machine: String address = "myremote.computer.com"; JSch jsch = new JSch(); String user = "tom"; String host = address; String password = "l33tpaSSw0rd"; Session

Jsch sftp channel state impact by previous channel state of the same session?

馋奶兔 提交于 2019-12-25 06:32:43
问题 In my code I am trying to keep the Jsch session active cause I expect many interactions with the server will happen. And the logic is: One thread will open channel on the session to check if a file exists Another thread try to open channel on the same session to send a file to the server However I found if #1 give me a "file not found", #2 will fail with the same exception at here: Header header=new Header(); header=header(buf, header); int length=header.length; int type=header.type; fill(buf

Mulesoft SFTP connector <service-overrides messageReceiver=“my.package.mySftpMessageReceiver”/> + JSch not working properly

百般思念 提交于 2019-12-25 03:17:24
问题 I am using Anypoint Studio to upsert product items from SFTP to Salesforce. I created a class mySftpMessageReceiver that extends sftpMessageReceiver and overrides the poll() function. In the poll() function I wrote, I am creating an instance of the class JSchSFTPBrowser I wrote. It uses the JSch Library. In this class, there's a function that takes rootDirectory and fileName as parameters. It looks recursively in all subfolders of rootDirectory for files having name containing fileName and

JSch: sudo <some command> sometimes not working

百般思念 提交于 2019-12-24 15:34:34
问题 I have three machines and I need to ssh to them one by one, and then sudo a command. I need the JSch to do the following things: ssh <user>@<machine> sudo <some command> This is the code block how I use to run JSch: String homeFolder = System.getProperty("user.home"); JSch jsch = new JSch(); jsch.addIdentity(homeFolder + "/.ssh/id_rsa.pub"); jsch.setKnowHosts(homeFolder + "/.ssh/known_hosts"); final Session session = jsch.getSession(user, machine); session.connect(); StringBuilder response =

com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 No appropriate prime between 1024 and 1024 is available. en

北战南征 提交于 2019-12-24 14:43:23
问题 I am looking to connect to a server where they support the following key exchange method ecdh-sha2-nistp521 ecdh-sha2-nistp384 ecdh-sha2-nistp256 diffie-hellman-group-exchange-sha256 diffie-hellman-group14 diffie-hellman-group I am using jsch jsch-0.1.53 and using RSA private/public key to connect to the server. This works fine before not until the server was changed and now returning this strange error com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 No appropriate prime between 1024

java jsch SSH_MSG_DISCONNECT Failed to read binary packet data

 ̄綄美尐妖づ 提交于 2019-12-24 11:35:36
问题 So I use a private key to connect to the sftp server ,so it came back error: com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 2 Failed to read binary packet data! Here is the code: JSch jsch = new JSch(); jsch.addIdentity(new File(privateKey).getAbsolutePath()); session = jsch.getSession(ftpUserName, ftpHost, ftpPort); LOGGER.debug("Session created."); if (ftpPassword != null) { session.setPassword(ftpPassword); } Properties config = new Properties(); config.put("StrictHostKeyChecking", "no

com.jcraft.jsch.JSchException: Auth fail error

余生长醉 提交于 2019-12-24 04:10:30
问题 Trying to connect to a host using ssh key auth. Below is my code: package com.mkyong.common; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.Session; /** * */ public class UserAuthPubKey { /** * @param args the command line arguments */ public static void main(String[] args) { try { JSch jsch = new JSch(); String user = "XXXXXXXX"; String host = "XXXXXXXX.XXXXXXX.com"; int port = 22; String privateKey = "~/.ssh/WF_OPENSSH