SSH (Secure Shell) is a network protocol that allows users to securely access and control remote computers or devices over an unsecured network. It provides a secure way to log in to a remote system and execute commands as if you were physically present at the machine. In this article, we will discuss how to set up an SSH connection between two machines that are connected to different routers within your home network.
Prerequisites
Before we begin, make sure you have the following:
- Two machines (e.g., laptops or desktops) connected to separate routers within your home network.
- Administrative access to both routers.
- Basic knowledge of networking concepts.
Step 1: Configure Port Forwarding on the First Router
To establish an SSH connection between two machines on different routers, we need to configure port forwarding on each router. Port forwarding allows incoming traffic on a specific port to be redirected to a specific machine on the network.
1. Connect to the administration interface of the first router by opening a web browser and entering the router's IP address (e.g., 192.168.1.1) in the address bar.
2. Log in to the router using the administrator credentials. If you haven't changed them, check the router's documentation for the default username and password.
3. Look for the "Port Forwarding" or "Virtual Server" section in the router's settings. The exact location may vary depending on the router model and firmware.
4. Add a new port forwarding rule by specifying the following details:
- Service/Port: Enter "SSH" or "22" (the default SSH port).
- Internal IP/Device: Enter the local IP address of the machine you want to connect to via SSH. You can find this IP address on the target machine by opening a command prompt and typing "ipconfig" (Windows) or "ifconfig" (Linux/macOS).
- Protocol: Select "TCP" as the protocol.
5. Save the changes and exit the router's administration interface.
Step 2: Configure Port Forwarding on the Second Router
Next, we need to configure port forwarding on the second router to allow SSH traffic to reach the target machine connected to it.
1. Connect to the administration interface of the second router using the same process as in Step 1.
2. Navigate to the "Port Forwarding" or "Virtual Server" section, similar to the first router.
3. Add a new port forwarding rule with the following details:
- Service/Port: Enter "SSH" or "22".
- Internal IP/Device: Enter the local IP address of the target machine connected to the second router.
- Protocol: Select "TCP".
4. Save the changes and exit the router's administration interface.
Step 3: Find Your Public IP Address
To connect to the target machine from outside your home network, you need to know your public IP address. This address is assigned by your internet service provider (ISP) and can change periodically.
1. Open a web browser on any machine within your home network.
2. Search for "what is my IP" using a search engine.
3. Note down the IP address displayed on the search results page. This is your public IP address.
Step 4: Connect to the Target Machine
Now that we have set up port forwarding on both routers and obtained the public IP address, we can connect to the target machine via SSH.
1. Open an SSH client on your local machine. If you are using Windows, you can download and install a client like PuTTY. For Linux and macOS, you can use the built-in terminal.
2. Enter the following command, replacing "public_ip_address" with your actual public IP address:
ssh username@public_ip_address
3. If this is the first time connecting to the target machine, you may see a warning about the authenticity of the host. Type "yes" to proceed.
4. Enter the password for the target machine when prompted. If the password is correct, you should now be connected to the remote machine via SSH.
Setting up an SSH connection between two machines connected to different routers within your home network may seem complex, but by following the steps outlined in this article, you can establish a secure and convenient way to remotely access and control your devices. Remember to configure port forwarding on both routers and keep your public IP address handy for connecting from outside your home network.
References
| Number | Source |
|---|---|
| 1 | https://www.ssh.com/ssh/ |
| 2 | Router manufacturer documentation |