Editing
SSH Tunnel
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Objective == Create an SSH tunnel on a local machine which redirects MySQL requests to another machine on the LAN. == Establish SSH Tunnel == Use `ssh` to create the tunnel that open up a socket listening to a port on the local machine and forward request to that local port to the port specified on the remote machine. <ref>[https://www.studytonight.com/post/how-to-setup-ssh-tunneling-in-mac-os-or-ubuntu How to Setup SSH Tunneling in Mac OS or Ubuntu]</ref> <pre> $ ssh -fN -L 8888:[REMOTE_SERVER]:3307 -p [NONSTANDARD_SSH_PORT] [USER]@[REMOTE_SERVER] </pre> * `-f` Run the ssh command in the background * `-N` Don't execute any commands on the remote machine. Just forward the port. * `-L` Binds the local port to the remote port. <ref>[https://explainshell.com/explain?cmd=ssh+-L+-N+-f+-l SSH options] - explainshell.com</ref> * `-p` Non standard SSH port number. This is for establishing the SSH connection with the remote host. It has nothing to do with the port forwarding. * 8888 is an arbitrary non-standard MySQL/MariaDB port to open on the local machine. Requests to this port are forwarded to the remote machine. * 3307 is the port on the remote machine to which requests will be forwarded, e.g. 3307, the standard MariaDB port. == Troubleshooting == === View SSH tunnels === <pre> $ lsof -i tcp | grep ^ssh ssh 18250 damien 3u IPv4 0xf863dcf7cc3dd6d5 0t0 TCP 192.168.123.105:56935->ds920:21098 (ESTABLISHED) ssh 18250 damien 5u IPv6 0xf863dcf7ce5b1e1d 0t0 TCP localhost:ddi-tcp-1 (LISTEN) ssh 18250 damien 6u IPv4 0xf863dcf7c661454d 0t0 TCP localhost:ddi-tcp-1 (LISTEN) </pre> === Destroy an SSH tunnel === Find the process id of the ssh tunnel. <ref>[https://stackoverflow.com/a/9532938 How do I close this SSH tunnel?] - StackOverflow</ref> <pre> $ ps aux | grep [LOCAL_PORT_NUMBER] </pre> Kill the process of the ssh tunnel. <pre> $ kill -9 [PID] </pre> == See Also == === Reference === <references />
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information