SSH connection with Java

Use JSch import com.jcraft.jsch.*; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; /** * @author World */ public class SSHReadFile { public static void main(String args[]) { String user = “john”; String password = “mypassword”; String host = “192.168.100.23”; int port = 22; String remoteFile = “/home/john/test.txt”; try { JSch jsch = new JSch(); Session session = … Read more

SSH tunneling from Heroku

Yes, you can. Having now gone down this path: yes, it is possible to set up an SSH tunnel from heroku to an external database. [NOTE: My particular app was written in Ruby on Rails, but the solution given here should work for any language hosted on Heroku.] Statement of the problem I am running … Read more

git clone hangs forever on github

GitHub offers a few different ways to connect to the remote repo. I am behind an onerous firewall. All methods also hang except using http (not https). For example, the JavaHamcrest project offers (anonymously): https://github.com/hamcrest/JavaHamcrest.git git@github.com:hamcrest/JavaHamcrest.git git://github.com/hamcrest/JavaHamcrest.git You may also try: http://github.com/hamcrest/JavaHamcrest.git Finally, prefix your UNIX command with GIT_TRACE=1 and GIT_CURL_VERBOSE=1, and use Git option … Read more

JConsole over ssh local port forwarding

There’s an even nicer way to do this using an SSH socks tunnel, since JConsole supports SOCKS: Create the SSH socks proxy locally on some free port (e.g. 7777): ssh -fN -D 7777 user@firewalled-host Run JConsole by specifying the SOCKS proxy (e.g. localhost:7777) and the address for the JMX server (e.g. localhost:2147) jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=7777 … Read more

How can you get the SSH return code using Paramiko?

A much easier example that doesn’t involve invoking the “lower level” channel class directly (i.e. – NOT using the client.get_transport().open_session() command): import paramiko client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(‘blahblah.com’) stdin, stdout, stderr = client.exec_command(“uptime”) print stdout.channel.recv_exit_status() # status is 0 stdin, stdout, stderr = client.exec_command(“oauwhduawhd”) print stdout.channel.recv_exit_status() # status is 127