SSH: Practical Guide for Developers


It's common that your server(destination_server) is running in cloud(AWS) which you have to access via another linux server(proxy_server), and you want to enable remote debug in the destination_server.

To do this, run this in the proxy_server:
ssh -f -N -L9999:localhost:9999 username@destination_server

Run this in your local server:
ssh -f -N -L9999:localhost:9999 username@proxy_server

In your destination_server, add this to the command that is used to start your server.
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999

Then start remote application in eclipse that connects to localhost:9999.

-- If Eclipse is very slow in remote debug mode, try to remove (all) breakpoints and expressions in eclipse.

-- Use ssh tunnel, you can do a lot of other stuff.
-- We can use ssh tunnel to test code locally without really deploy to aws.

ssh -f -N -L18983:remote-host:remote-port $USER@host-in-middle

SOCKS and dynamic port forwarding
1. .ssh/config
host server
  DynamicForward 1080


2. ssh -fND localhost:1080 bastion_server
ssh -fND 1080 bastion_server

curl --socks5 localhost:1080 remote_url

Java code
-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=3000
System.setProperty("socksProxyHost", "127.0.0.1");

System.setProperty("socksProxyPort", "3000");


Install Proxy SwitchySharp in Chrome

-f  send this ssh operation into the background after password prompts
-N do not execute remote command or wait for the user to provide any commands
-L static port forward
-D the local port to listen on
  - for dynamic port forwarding

Related
Create tunnel to remote Cassandra via man-in-the-middle
ssh -f host-in-middle -L 9042:destination-cassandra-server:9042 -N -v

Resources
SSH Tunneling Explained
SSH Tunnel - Local and Remote Port Forwarding Explained With Examples

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)