Difference between revisions of "SSH Forwarding"

From Nuclear Physics Group Documentation Pages
Jump to navigationJump to search
 
 
Line 1: Line 1:
 
To access web interfaces on other systems, use SSH port forwarding, like so:
 
To access web interfaces on other systems, use SSH port forwarding, like so:
  
ssh -L [localport]:localhost:[foreignport] remotehost
+
ssh -L [localport]:foreign-system:[foreignport] tunnel-system
  
As long as that ssh connection is valid, you can access the remote host's port by accessing localhosts's localport.
+
This makes a connection     yourmachine:localport <-> <tunnel-system> <-> foreign-system:foreignport
  
'''Note:''' In order to forward privileged ports, you need root access.
+
So, from your local system to open a mysql connection to "roentgen", use:
 +
 
 +
  ssh -L 33306:roentgen:3306 gourd.unh.edu
 +
 
 +
You can now use mysql as if it is running locally on port 33306:
 +
 
 +
  mysql -P 33306 -h 127.0.0.1 -p
 +
 
 +
Note: yes, you must use -h 127.0.0.1, or else mysql will try /tmp/mysql.sock and fail to connect, since it is trying your locally running mysqld.
 +
 
 +
'''Note:''' In order to forward privileged ports, you need root access. SO DON'T!

Latest revision as of 16:17, 25 December 2016

To access web interfaces on other systems, use SSH port forwarding, like so:

ssh -L [localport]:foreign-system:[foreignport] tunnel-system

This makes a connection yourmachine:localport <-> <tunnel-system> <-> foreign-system:foreignport

So, from your local system to open a mysql connection to "roentgen", use:

 ssh -L 33306:roentgen:3306 gourd.unh.edu

You can now use mysql as if it is running locally on port 33306:

 mysql -P 33306 -h 127.0.0.1 -p

Note: yes, you must use -h 127.0.0.1, or else mysql will try /tmp/mysql.sock and fail to connect, since it is trying your locally running mysqld.

Note: In order to forward privileged ports, you need root access. SO DON'T!