jsch

Executing sudo using SSH “exec” channel in JSch

雨燕双飞 提交于 2019-12-18 07:22:48
问题 I am using file in which I passed below commands: hostname pwd pbrun su - fclaim whoami cd .. pwd Ad the Java code below: for (String command1 : commands) { Channel channel=session.openChannel("exec"); ((ChannelExec)channel).setCommand(command1); in=channel.getInputStream(); channel.connect(); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0) break; System.out.println(new String(tmp, 0, i)); } if(channel.isClosed()){ break; } } channel

JSch: addIdentity from private key stored on hdfs [duplicate]

眉间皱痕 提交于 2019-12-18 07:07:29
问题 This question already has an answer here : JSch to add private key from a string (1 answer) Closed last year . I need to connect to an sftp server from an hadoop cluster. I would like to know if there is a way to load an identity from a private key stored in hdfs. Actually it seems that the JSch object accepts only a local path: try { String privateKeyPath = "hdfs://namenode:8020/path/to/privatekey"; // need this one to be an hdfs path JSch jsch = new JSch(); jsch.addIdentity(privateKeyPath);

JSch multiple tunnels/jumphosts

*爱你&永不变心* 提交于 2019-12-18 07:04:56
问题 I'm not sure if this is caused by using a private key instead of password for the port forwarding but here's what I'm trying to do I need to forward local port 3308 all the way to the my SQL DB at 3306. I can run things like this all together in terminal on my local ssh -L 3308:localhost:3307 username@jumpbox "ssh -L 3307:mysqlDB:3306 username@server" Or run the first part on my local and then the second part on the jumpbox. Both works fine and I can connect to my localhost:3308. The problem

Getting unwanted characters when reading command output from SSH server using JSch

痞子三分冷 提交于 2019-12-18 06:54:58
问题 I am connecting to the remote server SSH server and trying to get get the list of files in a particular path I am able to get list of files in the path but they were in unreadable format could any one help on this String host="xxxxx.yyyy.com"; String user="user"; String password="password"; String command1="dzdo su - lucy"; try{ java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); Session session=jsch.getSession(user,

Getting unwanted characters when reading command output from SSH server using JSch

為{幸葍}努か 提交于 2019-12-18 06:53:58
问题 I am connecting to the remote server SSH server and trying to get get the list of files in a particular path I am able to get list of files in the path but they were in unreadable format could any one help on this String host="xxxxx.yyyy.com"; String user="user"; String password="password"; String command1="dzdo su - lucy"; try{ java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); Session session=jsch.getSession(user,

JSch 0.1.53 session.connect() throws “End of IO Stream Read”

◇◆丶佛笑我妖孽 提交于 2019-12-18 05:49:12
问题 I downloaded a new JSch 0.1.53 library and JSch (sftp) download task no longer works. This release fails on session.connect() function throwing an error Session.connect: java.io.IOException: End of IO Stream Read . My old jsch.jar(2011-10-06) works fine to the same host, maybe I am missing a new config props? Session session=null; ChannelSftp channel=null; try { JSch.setLogger(SSHUtil.createJschLogger()); JSch jsch=new JSch(); session=jsch.getSession("myuser", "11.22.33.44", 22); session

How do I load optional task sshexec into Ant in a no-configuration manner?

偶尔善良 提交于 2019-12-17 21:31:51
问题 I am using sshexec, which depends on jsch-0.1.48.jar. I can't just put that into the ant/lib directory because other users wishing to use the same build script will have to make a configuration on their machine before they can do so. What I want to do is to be able to reference jsch-0.1.48.jar as part of the project. Currently, I have it sitting in project/libs directory and I am trying something like: <property name="lib" location="lib"/> <taskdef name="sshexec" classname="org.apache.tools

JSch - How to issue commands as the user I have switched to

时间秒杀一切 提交于 2019-12-17 21:29:53
问题 I am using Jsch to remotely connect to a Linux server from Windows 7. I have to (i) login to Linux server with my credentials (ii) switch to root using a pmrun command [this is the procedure in our environment], and (iii) execute su command to switch as "someuser" (iv) execute further commands as that "someuser" I completed the steps (i) and (ii). After completing step (ii), the InputStream from the channel shows the command-prompt as that of the root user. So I assume that I have become the

Running command after sudo login

耗尽温柔 提交于 2019-12-17 20:28:20
问题 I'm trying to execute below code to execute sudo commands but I do not know how execute commands after sudo login String[] commands = {"sudo su - myname;","id"}; JSch jsch = new JSch(); String username = "myuser"; com.jcraft.jsch.Session session = jsch.getSession(username,"hostname", 22); session.setPassword("my@123"); session.connect(); Channel channel=session.openChannel("exec"); for(int a=0;a<=commands.length;a++){ ((ChannelExec)channel).setCommand("sudo su - myname;"); ((ChannelExec

How to perform multiple operations with JSch

元气小坏坏 提交于 2019-12-17 20:24:08
问题 I am new to SSH and JSch. When I connect from my client to the server I want to do two tasks: Upload a file (using ChannelSFTP ) Perform commands, like creating a directory, and searching through a MySQL database At the moment I am using two separate shell logins to perform each task (actually I haven't started programming the MySQL queries yet). For the upload the relevant code is session.connect(); Channel channel=session.openChannel("sftp"); channel.connect(); ChannelSftp c=(ChannelSftp