Creating Remote Connections: Home Computer to Campus Intranet via Cloud
Published:
This guide explains how to set up remote connections from a computer on public Wi-Fi to a campus intranet server using a cloud computer, including SSH key generation, autossh installation, and automated service configuration.
Tutorial: Reverse SSH - Home Computer Connecting to Campus Intranet Server
This comprehensive guide provides step-by-step instructions on establishing remote connections for a computer connected to a public Wi-Fi network. The connections will be orchestrated through the use of a cloud-based computer, such as Amazon Cloud.
Terminology
- A: Refers to the computer connected to public Wi-Fi.
- B: Designates the cloud computer.
- C: Represents the laptop at home.
Setting Up the Connection from A to B:
- Generate an SSH Key Pair: Begin by creating an SSH key pair on computer A to facilitate passwordless login to computer B. Execute the following command:
ssh-keygen -t rsa # Press Enter for all prompts. The generated id_rsa.pub file will be located in the ~/.ssh/ directory. - Copy Public Key: Copy the public key from computer A to computer B using this command:
ssh-copy-id -i ~/.ssh/id_rsa.pub ubuntu@666.666.666.666 -p 22 - Install Autossh: Install
autosshto guarantee automatic reconnection in the event of a disruption in the reverse SSH connection between A and B:apt-get install autossh - Test Connection: Verify the success of the
autossh+ passwordless login setup by running the following command:autossh -M 9991 -NfR 8990:localhost:22 ubuntu@666.666.666.666If the command on computer A runs successfully, and on computer B, you observe the port numbers in the red box when executing the command
watch -n 1 netstat -tnlp, then the test is successful.
Configuring the Autossh Service:
- Automate Autossh Startup: Automate the startup of
autosshwhen computer A is powered on. Begin by creating anautossh.servicefile:vim /lib/systemd/system/autossh.serviceInsert the following content into the
autossh.servicefile:[Unit] Description=Auto SSH Tunnel After=network-online.target [Service] User=YOUR_USER_NAME Type=forking ExecStart=/usr/bin/autossh -NR 9888:localhost:22 -i /home/YOUR_USER_NAME/.ssh/id_rsa ubuntu@666.666.666.666 -p 22 >> /dev/null 2>&1 ExecReload=/bin/kill -HUP $MAINPID ExecStop=/bin/kill -TERM $MAINPID KillMode=process Restart=always [Install] WantedBy=multi-user.target WantedBy=graphical.target - Verify Configuration: Check if the
autosshservice is successfully configured:systemctl enable autossh systemctl start autosshConfirm the service’s status:
systemctl status autosshIf the service starts successfully, when running the command
watch -n 1 netstat -tnlpon computer B, you should see the port numbers in the red box.
Connection from C to A:
To establish a connection from laptop C to computer A through computer B:
- Connect to Computer B: Initiate an SSH connection to computer B using the following command:
ssh ubuntu@666.666.666.666 - Access Computer A: Open another terminal tab and connect to computer A:
ssh -p 9888 YOUR_USER_NAME@127.0.0.1You should now have a remote connection from laptop C to computer A via computer B, enabling seamless access to your campus intranet server.
