To achieve this, you'll need to set up an SSH tunnel from your local machine to your VPS, and then connect to the Rcon server through this tunnel. Here's a step-by-step guide to help you accomplish this.
Step 1: Ensure You Have SSH Access to Your VPS
First, make sure you have SSH access to your VPS. You should have a username and password or SSH keys set up for authentication.
Step 2: Understand the SSH Tunnel Command
The SSH tunnel command is used to create a secure tunnel from your local machine to your VPS. The basic syntax for creating a tunnel is:
ssh -L local_port:localhost:remote_port username@vps_address
local_port is the port on your local machine that you will connect to.
remote_port is the port on your VPS where the Rcon server is running.
username is your username on the VPS.
vps_address is the IP address or domain name of your VPS.
Step 3: Set Up the SSH Tunnel to the Rcon Server
Let's say your Rcon server is running on port 25575 on your VPS, and you want to access it through port 25575 on your local machine. The command to create the tunnel would look like this:
ssh -L 25575:localhost:25575 username@vps_address -N
-N tells SSH not to execute a remote command (i.e., it just establishes the tunnel and doesn't open a shell).
However, to directly connect to the Rcon server after establishing the tunnel, we'll need to combine this with a command to connect to the Rcon server.
Step 4: Connecting to the Rcon Server
To directly connect to the Rcon server after establishing the tunnel, you can use a tool like rcon-cli (available for various platforms). First, you'll need to install rcon-cli on your local machine.
For example, on Ubuntu/Debian, you can install it using:
sudo apt-get update && sudo apt-get install rcon-client
Or, you might need to build it from source or use a package manager relevant to your OS.
Step 5: Combining the Commands
To both establish the tunnel and connect to the Rcon server, you can use a command like this:
ssh -L 25575:localhost:25575 username@vps_address -N &
rcon-cli -a localhost:25575 -p your_rcon_password
However, running the SSH command with -N in the background (& at the end) might not be ideal as it leaves the tunnel running until you manually kill the process.
A better approach is to use a single command that establishes the tunnel and then connects to the Rcon server, without leaving the SSH connection running in the background:
ssh -t username@vps_address "rcon-cli -a localhost:25575 -p your_rcon_password"
But this requires rcon-cli to be installed on the VPS, not your local machine.
If you want to keep it on your local machine, you can create a simple bash script (for Linux/Mac) or a batch script (for Windows) that:
- Establishes the tunnel in the background.
- Waits a moment for the tunnel to be established.
- Connects to the Rcon server.
Here's a simple bash script example:
#!/bin/bash
# Establish the tunnel in the background
ssh -L 25575:localhost:25575 username@vps_address -N -f
# Wait a second for the tunnel to be established
sleep 1
# Connect to the Rcon server
rcon-cli -a localhost:25575 -p your_rcon_password
After creating the script, make it executable with chmod +x your_script.sh, and then you can run it.
For Windows, you can create a similar batch script or use a tool like PuTTY to establish the tunnel and then connect using rcon-cli.
Security Note
- Always ensure you're using a secure password or SSH keys for your VPS.
- Be cautious with scripts that contain passwords. Consider using more secure methods like SSH keys or environment variables for sensitive information.
This guide should help you set up a simple and secure way to connect to your Rcon server via an SSH tunnel.