{
"$type": "site.standard.document",
"description": "Nice flag to remember when debugging internal applications on remote servers.",
"path": "/blog/port-forwarding-through-ssh/",
"publishedAt": "2025-01-19T00:00:00.000Z",
"site": "at://did:plc:3nlkmby2zllrhcj6z5dnicui/site.standard.publication/3mnr22gea2o2d",
"textContent": "While working on my undergraduate senior thesis a few years ago, I made a small web application to visualize certain patterns as my daily experiments went through. This application was running inside a remote server and was not getting exposed to the public internet, so it was a hassle to check its content.\n\nAfter trying to figure out a way to make it easier to access said application, I stumbled upon the port forwarding functionality of ssh. I'm writing this brief explanation many years later to prevent myself from forgetting it again.\n\nAs per ssh's man page, you can use the -L flag to specify \"that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side\".\n\nPractically speaking, if your remote server is located at example.com and is running an application that listens for connections on port 8001, you can run this command on your local machine:\n\nssh user@example.com -L 3000:localhost:8001\n\nYou can read the 3000:localhost:8001 part as \"connections to (my local) port 3000 is to be forwarded to the remote server, to the localhost host and the 8001 port\". Adjust the ports and host to suit your use case.\n\nWhile this ssh session is running, you can access localhost:3000 on your local machine and you should be greeted by whatever is available on localhost:8001 on the remote machine. Nice!",
"title": "Port forwarding through SSH"
}