Author: Rodrigo Marinao Rivas

The ability to access and control resources on remote servers is essential for various hydroinformatics activities. This need arises when working in a distributed environment or requiring access to specific resources hosted on a network-connected computer.

The main challenge lies in how to access these computers securely and efficiently, particularly in corporate networks or when handling sensitive data. To tackle this challenge, it is essential to use three basic tools: VPN, SSH, and Screen. These tools, when used together, enable proper workflows for managing computational infrastructure. Let’s briefly review each tool and how their combined use facilitates the implementation of an effective practical case.

VPN (Virtual Private Network)

A VPN establishes a secure connection to a remote server from a device located in another local network. This secure connection is essential to protect the confidentiality and integrity of the data transmitted between both points. In an academic or corporate environment, a VPN is commonly used to allow students and/or employees to securely access the company’s internal network from external locations.

SSH (Secure Shell)

SSH provides a secure way to access and manage a remote server through an encrypted connection. Once connected to the server via SSH, you can execute commands on the server’s terminal as if you were physically present. This is critical for performing administrative tasks, configurations, and running scripts on the server.

The most common SSH commands include:

  • ssh user@server: Starts an SSH session on the remote server.
  • ssh -p port user@server: Specifies a custom port for the SSH connection.
  • ssh-keygen: Generates a public and private key pair for passwordless SSH authentication.
  • ssh-copy-id user@server: Copies the public key to the remote server for passwordless authentication.

Screen

Screen is a tool that allows the creation of virtual terminal sessions that persist even after closing the SSH connection. This is useful when you need to run a long process or want to ensure it continues if the connection is lost.

Some useful Screen commands include:

  • screen: Creates a new Screen session.
  • screen -ls: Lists all active Screen sessions.
  • screen -r session_name: Reconnects to an existing Screen session.
  • Ctrl + A, D: Detaches the Screen session without closing it.
  • Ctrl + A, C: Creates a new window within the Screen session.
  • Ctrl + A, N: Switches to the next window within the Screen session.
  • Ctrl + A, P: Switches to the previous window within the Screen session.

By combining VPN, SSH, and Screen, you can establish a secure remote connection and keep processes running on remote servers without fear of interruptions.

Practical Example: Executing a Task on a Remote Server

Step 1: Establish a VPN Connection with FortiClient

Open FortiClient and establish a VPN connection to the remote server.

Step 2: SSH Connection to the Remote Server

Open your computer’s terminal and execute the following command to connect to the server:

ssh user@remote_server

Step 3: Create and Use a Screen Session

Once connected to the server, create a new Screen session with a custom name:

screen -S my_session

Run the task you want to execute within the Screen session. For example:

python3 my_script.py

Press Ctrl + A, followed by D to detach from the Screen session and leave the task running in the background.

Step 4: Resume the Screen Session

To resume the Screen session and check the task’s status, reconnect to the server via SSH and execute:

screen -r my_session

This will bring you back to the Screen session. If the session was “detached,” it means the session was in the background, but the task continued running. If the session was “attached,” it means you are actively interacting with the Screen session and the task.

Conclusion

By using a combination of VPN, SSH, and Screen, you can execute a task on a remote server securely and efficiently, even if you disconnect from the network. This approach allows you to manage resources on remote servers effectively and without interruptions.