This repository provides a Google Colab notebook for setting up and running a Minecraft server with SSH tunneling. This allows you to host a Minecraft server directly from your Google Colab environment, accessible to others via a public IP address.
Note: Remember to replace YOUR_USERNAME and YOUR_REPOSITORY_NAME in the "Open In Colab" badge link above with your actual GitHub username and repository name.
- Easy Setup: Automates most of the setup process for a Minecraft server.
- SSH Tunneling: Uses
portmap.ioto create an SSH reverse tunnel, making your server accessible from outside Google Colab. - Google Drive Integration: Stores server files on Google Drive, allowing for persistence across Colab sessions.
- Minecraft Version 1.21.3: Downloads and runs this specific version of the Minecraft server.
Before running the notebook, ensure you have the following:
- Google Drive Access: The notebook will mount your Google Drive to store server files.
- SSH Key File: A private SSH key file (e.g.,
qasw1234.first.pem) is required for SSH tunneling. This file should be placed in the/content/drive/MyDrive/ms/directory. - Portmap.io Account: You'll need an account with
portmap.ioto set up the SSH tunnel.
Follow these steps to set up and run your Minecraft server:
These steps only need to be performed once.
- Open the Notebook in Colab: Click the "Open In Colab" badge above or upload the
Minecraft_hosting.ipynbfile to Google Colab. - Clean up existing Java installations: Run the cell with
!sudo apt purge openjdk-* -yand!sudo apt autoremove -yto ensure no conflicting Java versions are present. - Mount Google Drive and Create Server Directory: Run the cell that mounts Google Drive and creates the
/content/drive/MyDrive/msdirectory. This is where your Minecraft server files will be stored. - Download Minecraft Server JAR: Execute the cell that downloads
server.jarfor Minecraft version 1.21.3. - Place SSH Key: Ensure your SSH key file (e.g.,
qasw1234.first.pem) is placed inside/content/drive/MyDrive/ms/.
These steps need to be performed every time you want to start your Minecraft server.
- Install OpenJDK 21: Run the cell to install OpenJDK 21.
- Verify Java Installation: Run the cell to confirm Java is correctly installed by checking its version.
- Navigate to Server Directory and Set SSH Key Permissions: Change the directory to
/content/drive/MyDrive/msand set the correct permissions for your SSH key file (chmod 600 your_key_file.pem). - Start Minecraft Server and SSH Tunnel: Run the final code cell. This script will:
- Remove any existing
session.lockfile to prevent startup issues. - Start the Minecraft server with 6GB initial RAM and 8GB maximum RAM.
- Establish an SSH reverse tunnel from your
portmap.ioendpoint to your local Minecraft server portlocalhost:25565.
- Remove any existing
To create the necessary SSH tunnel for your Minecraft server, follow these steps on Portmap.io:
- Log in to Portmap.io: Go to the Portmap.io website and log in to your account.
- Generate SSH Key (if not already done): Portmap.io usually provides instructions to generate an SSH key pair. You'll need the private key (which you'll upload to your Colab environment, named something like
qasw1234.first.pem). - Add a New Mapping:
- Navigate to the "Mappings" or "Tunnels" section.
- Click on "Add New Mapping" or a similar option.
- Public Port: This is the port on Portmap.io that your Minecraft clients will connect to. Choose a free port (e.g.,
61819). - Private IP: Set this to
localhost. - Private Port: Set this to
25565(the default Minecraft server port). - Protocol: Select
TCP. - Description (Optional): Add a descriptive name like "Minecraft Server".
- Connect to your Mapping: After creating the mapping, Portmap.io will provide you with the connection details, including the Public Host and Public Port. This will be in the format
your_username-your_port.portmap.io:your_port(e.g.,demo.portmap.io:61819). You'll use this information in the SSH command within the Colab notebook.
- Monitoring Output: The notebook will display output from both the Minecraft server (prefixed with
[MC]) and the SSH tunnel (prefixed with[SSH]). - Sending Commands: You can type Minecraft server commands directly into the input prompt provided by the Colab cell.
- Stopping the Server: Type
exitin the input prompt and press Enter to gracefully stop the Minecraft server and the SSH tunnel.
Once the server is running and the SSH tunnel is active, your Minecraft server should be accessible at the Public Host and Public Port provided by your Portmap.io mapping (e.g., demo.portmap.io:61819). This address maps to localhost:25565 on the Colab instance.
server.jarnot found error: Ensure you have run the "Download Minecraft server" cell and thatserver.jarexists in/content/drive/MyDrive/ms/.- SSH tunnel connection issues:
- Verify your private key file is correctly placed and has the right permissions (
chmod 600). - Double-check your
portmap.iodetails and ensure the tunnel is active on their side. - Review the
[SSH]output for any error messages.
- Verify your private key file is correctly placed and has the right permissions (
- Minecraft server not starting: Check the
[MC]output for any error messages. This might indicate issues with Java, server properties, or world data. If asession.lockfile exists from a previous improper shutdown, the script attempts to remove it, but manual intervention might be needed for other issues. - "SERVER IS RUNNING IN OFFLINE/INSECURE MODE!": This is a warning from Minecraft itself. By default, the
server.propertiesfile hasonline-mode=false. While this allows players without a premium Minecraft account to join, it also means usernames are not authenticated, making your server vulnerable to impersonation. For a secure server, setonline-mode=trueinserver.properties(though this would require a premium account for players).