
{{ $('Map tags to IDs').item.json.title }}
How to Forward Ports with SSH
Port forwarding with SSH allows you to securely access services running on remote machines by tunneling through an SSH connection. This is a useful technique for accessing applications that are not publicly accessible or for securing data transmitted over insecure networks. This tutorial will guide you through the process of forwarding ports using SSH.
1. Understanding SSH Port Forwarding
SSH tunneling can be done in two ways:
- Local Port Forwarding: Forwards a port on your local machine to a port on a remote server.
- Remote Port Forwarding: Forwards a port on the remote server to a port on your local machine.
2. Local Port Forwarding
To forward a local port to a remote server, use the following syntax:
ssh -L local_port:remote_host:remote_port username@ssh_server
Here’s what each parameter means:
- local_port: The port on your local machine that will be forwarded.
- remote_host: The destination server that is running the service you want to access.
- remote_port: The port on the remote host (the service you want to access).
- username: Your SSH username on the remote server.
- ssh_server: The IP address or hostname of the SSH server.
For example, to forward local port 8080 to access a web server running on port 80 of a remote server:
ssh -L 8080:localhost:80 username@ssh_server
You can then access the remote web server by navigating to http://localhost:8080
on your web browser.
3. Remote Port Forwarding
To forward a remote port to your local machine, use the following syntax:
ssh -R remote_port:localhost:local_port username@ssh_server
This allows users on the remote server to access a service running locally. For example:
ssh -R 9090:localhost:3000 username@ssh_server
This command forwards port 9090 on the remote server to port 3000 on your local machine.
4. Using SSH Keys for Easier Access
To avoid entering your password every time you initiate an SSH connection, consider setting up SSH key authentication. Check out our tutorial on setting up SSH keys for secure authentication.
5. Conclusion
By following this tutorial, you have learned how to forward ports using SSH. Port forwarding provides a secure way to access services on remote servers, greatly enhancing flexibility and security. Continue exploring additional SSH features to optimize your remote access configurations!