lichess.org
Donate

Creating Your Own Stockfish in the Cloud

ChessChess engineSoftware Development
Setting up Stockfish in the cloud can be a game-changer for chess enthusiasts and professionals alike. By leveraging the power of cloud computing, you can access high-performance chess analysis from any device, even if your personal laptop or desktop is underpowered. Whether you want faster calculations, the ability to run multiple analysis sessions, or just the convenience of a persistent remote setup, the cloud offers an ideal solution.

### IMPORTANT

I just received word that Digital Ocean charges for CPU and RAM even though the service is switched off, as such, I will be adjusting this guild to use a different cloud provider, the steps should almost be identical. Amazon AWS, Google, Microsoft Azure who do charge if your platform is not running, but a minimal amount for storage. If you have followed this guide, please tear down your Droplets immediately to avoid costs and raise a ticket to complain about this, as it is not how most cloud computing organisations work. My sincerest apologies. I did not read the fine print and assumed that this was like most cloud platforms

Recently, IM David Shahinyan reached out to me with a simple yet intriguing question: “Have you ever set up Stockfish in the cloud?” I hadn’t, but the idea immediately sparked my interest. It made perfect sense—cloud computing could provide unmatched power and flexibility for chess analysis, especially for those with hardware limitations. Inspired by his question, I decided to give it a shot.
At first, I turned to online guides, hoping to find a straightforward solution. Unfortunately, most of the guides I came across were either too complex, incomplete, or didn’t quite work for me. After several failed attempts to get them fully working, I realized the best way forward was to start from scratch. I wanted to create a method that worked reliably and, just as importantly, document it in a clear and accessible guide to help others avoid the same frustrations I faced.
This guide is designed specifically for Windows users. Along the way, we’ll install a few key pieces of software, do some light programming, and tackle the entire process step by step. I’ll include as much detail as possible to ensure you can follow along, whether you’re tech-savvy or completely new to cloud computing. By the end, you’ll have a fully functional cloud-based Stockfish setup—and hopefully learn a few new skills in the process! Let’s dive in and make this journey a success.

1. PuTTY

PuTTY is a free tool that helps you connect to other computers over the internet. Think of it as a remote control for a computer that’s far away—in this case, our cloud server. We’ll use PuTTY to securely log into the server, send commands, and manage it from your own computer.
PuTTY also includes some helpful tools, like PuTTYgen, which we’ll use to create special keys that act like passwords but are more secure. These keys will help ensure that only you can access your server.
In this guide, PuTTY will help us:

  1. Connect to the Cloud Server: It allows us to log in to our cloud server and control it remotely.
  2. Generate Security Keys: PuTTYgen, one of its tools, lets us create a secure way to access the server without needing to type a password every time.

Steps to Install PuTTY

  1. Download PuTTY:
    • Go to the official PuTTY website: https://www.putty.org.
    • Download the PuTTY installer for Windows. If you’re not sure which version to pick, choose the 64-bit version, as most modern computers support it.
  2. Install PuTTY:
    • Double-click the downloaded file and follow the instructions to install PuTTY.
    • Make sure you include PuTTYgen during the installation (it’s usually selected by default).
  3. Generate Your Public and Private Keys:
    • Open PuTTYgen (it will be listed in your Start menu or desktop after installation).
    • Click Generate, and move your mouse around the empty area to create randomness for the keys.
    • Once the keys are created:
      • Save the private key to your computer in a safe place. Name it something like private.key.ppk and keep it secure.
      • Save the public key as a separate file, such as public.key.pub, in the same folder.
    • (Optional) You can set a passphrase for your private key. This adds an extra layer of protection if someone gains access to your private key file.

What Are Private and Public Keys, and Why Are They Important?
Private and public keys are like a special pair of digital locks and keys that work together to secure your connection to a server. The private key is your secret key, which you must keep safe and never share with anyone. It’s like a master key that allows you to unlock access to your server. The public key, on the other hand, is meant to be shared. It’s like a lock you give to the server, which can only be unlocked by your private key.
This method of security, called public-key cryptography, ensures that only someone with the matching private key (you) can access the server. It’s much safer than a traditional password because even if someone intercepts the public key, they cannot guess the private key. By using this system, you can protect your server from unauthorized access and ensure a secure, encrypted connection for managing it remotely.

That’s it! You’ve installed PuTTY and prepared your security keys, which we’ll use to access the cloud server in the next step.

2. Setting Up Your Server

A cloud platform is like renting a powerful computer that lives on the internet. It allows you to run programs and store data without relying on your own hardware. For this guide, we’ll use DigitalOcean, a popular cloud service that is beginner-friendly, cost-effective, and provides all the features we need to set up Stockfish.
With DigitalOcean, you can create a virtual server (called a “droplet”) that runs 24/7 and is powerful enough to handle complex chess calculations. You also have the flexibility to switch the droplet on and off as needed, saving costs when it’s not in use.
Why DigitalOcean?

  • Ease of Use: Its interface is simple and intuitive, making it a great choice for first-time users.
  • Affordable Pricing: You can start with a droplet for as little as $6/month.
  • Performance: A server with 4GB of RAM is sufficient for Chessbase and Stockfish.

If you’d like to explore alternatives, here are some other widely used cloud platforms:

  • Amazon Web Services (AWS): Offers a free tier but has a steeper learning curve.
  • Google Cloud Platform (GCP): A flexible and scalable option with a free trial.
  • Microsoft Azure: Great for integration with other Microsoft products but more enterprise-focused.

Important Note

Cloud services will charge you while the server is running, even if you’re not actively using it. To avoid unnecessary costs, make sure to switch off the server when you don’t need it. Forgetting to turn it off can lead to unexpected charges. Additionally, when selecting a droplet size, you’ll see both the hourly and monthly costs. Keep this in mind to choose a plan that fits your budget and usage needs

Step 1: Sign Up for DigitalOcean

  • Go to https://www.digitalocean.com and create an account.
  • Provide your billing information and take advantage of the free trial for new users.

If you’d like to support my work, you can use the following affiliate link to sign up for DigitalOcean: https://m.do.co/c/21fa2a3f2212. You’ll receive $200 in free credits, and I’ll earn additional credits as well, which helps me continue creating content like this.

Step 2: Create a Droplet

  • Log in to your account and click Create Droplet.
  • Choose Ubuntu as the operating system. This is a stable and popular Linux distribution suitable for running Stockfish.

Step 3: Configure the Droplet

  • Select a droplet with at least 4GB of RAM to ensure Stockfish runs smoothly.
  • Review the hourly and monthly costs to select a plan within your budget.
  • Choose a data center region closest to your location for better performance. For example, if you're in North America, choose New York or San Francisco. If you're in Europe, consider Frankfurt or London.

Step 4: Add Your Public Key

  • Select SSH Keys under authentication and click New SSH Key.
  • Open your public.key.pub file in a text editor like Notepad.
  • Copy only the key content without the ---- BEGIN SSH2 PUBLIC KEY ---- or ---- END SSH2 PUBLIC KEY ---- lines.
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20250120"
AAAAB3NzaC1yc2EAAAADAQABAAABAQC9XA2JVNQrNwVnu2k+O6hnAH6W+93Dr0Q7
p6Z6VM8MUnxAooAyeqsZmGTgfxwzQ5jMMnqXV+pqBjT/yrQDnFV/9ubZFO/okHe+
ckORuqNyEs++iqMFl4yzLAViJ2O6miKVveVJwFcRsueuvidC4/BNPiFVGyTR7xMW
BLvaknSzF4i16zAo/n41h8OFIUuhW+HT4+HWhIKqOqqaqszUPyTe6I8XHxpp18sX
r75RCwClxPY1o54lfY7BzaTYUEx/0hS6kLyulZNCB3g+985+tDL+GQHU3P3aJLr5
7ZOWtzvf9fcv3dlmx7ZERjccX9XIdCcl8JrGWuWrlIgpbDHBoMgT
---- END SSH2 PUBLIC KEY ----
  • Combine the lines into one continuous string and add ssh-rsa at the beginning of the key, followed by a space. For example:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9XA2JVNQrNwVnu2k+O6hnAH6W+93Dr0Q7p6Z6VM8MUnxAooAyeqsZmGTgfxwzQ5jMMnqXV+pqBjT/yrQDnFV/9ubZFO/okHe+ckORuqNyEs++iqMFl4yzLAViJ2O6miKVveVJwFcRsueuvidC4/BNPiFVGyTR7xMWBLvaknSzF4i16zAo/n41h8OFIUuhW+HT4+HWhIKqOqqaqszUPyTe6I8XHxpp18sXr75RCwClxPY1o54lfY7BzaTYUEx/0hS6kLyulZNCB3g+985+tDL+GQHU3P3aJLr57ZOWtzvf9fcv3dlmx7ZERjccX9XIdCcl8JrGWuWrlIgpbDHBoMgT

Important Note

This has to be a single line otherwise you will get a error.

  • Paste this single-line key into the Ssh Key Content box.
  • Give the key a recognizable name, such as MyLaptopKey.

Step 5: Finalize and Test the Connection

  • Click Create Droplet to complete the setup. DigitalOcean will display the droplet's IP address (something like 161.35.239.189) once it’s ready.
  • Open PuTTY and enter the droplet’s IP address in the Host Name field.
  • Add your private key by navigating to Connection > SSH > Auth in PuTTY’s settings and selecting your private.key.ppk file.
  • Click Open to connect to your droplet. Log in as root (the default user). Since you’re using an SSH key, you won’t need a password.

Note: When you connect to your droplet using PuTTY for the first time, you may see a security alert stating, “The server’s host key is not cached in the registry.” This message is normal and occurs because PuTTY has not seen the server’s key before. Simply click Accept to proceed. This will cache the server’s key for future connections, ensuring secure and seamless logins.

In this section, you learned how to set up a DigitalOcean droplet, configure it with the right specifications, and securely connect using an SSH key to prepare for running Stockfish in the cloud.

3. Installing Stockfish on Your Ubuntu Server

Stockfish is one of the strongest open-source chess engines in the world. By installing it on your cloud server, you can leverage its power for high-performance analysis, regardless of your local machine's capabilities.

Step 1: Connect to Your Ubuntu Server

  • Open PuTTY and enter your droplet's IP address in the Host Name field.
  • Ensure your private key (private.key.ppk) is loaded under Connection > SSH > Auth.
  • Click Open to connect to your server.
  • Log in as root (the default administrator user). You won’t need to enter a password since you’re using an SSH key.

Step 2: Update Your System

  • Run the following commands to ensure your server is up-to-date: sudo apt update and then sudo apt upgrade -y
  • These commands update the list of available packages and install the latest updates for all installed software.

Note: During the installation or update process, you may be prompted with a message about OpenSSH configuration changes, asking whether to keep the local version or install the package maintainer's version. Select Keep the local version installed to avoid overwriting any custom SSH configurations you may already have set up. This ensures your existing SSH connection settings remain intact.

What is apt?
apt (Advanced Package Tool) is a command-line tool used in Ubuntu and other Debian-based Linux distributions to manage software packages. It allows you to:

  • Install software: Download and install applications from official repositories.
  • Update packages: Ensure installed software is up-to-date with the latest versions.
  • Remove software: Uninstall packages no longer needed.
  • Search for packages: Find software available in the repositories.

When you use apt, it ensures that all dependencies (additional software or libraries needed by the package) are installed automatically, making the process seamless.
For example:

  • sudo apt install stockfish installs Stockfish.
  • sudo apt update refreshes the list of available packages.
  • sudo apt upgrade upgrades all installed software to the latest versions.

What is sudo?
sudo stands for "superuser do" and is a command used to run tasks with administrative (root) privileges. Many system-level operations, like installing software or modifying system files, require elevated permissions for security reasons. Using sudo ensures that only authorized users can perform these tasks.
For example:

  • apt install stockfish will fail if run without sudo, as installing software requires administrative rights.
  • Adding sudo before the command, as in sudo apt install stockfish, temporarily grants the necessary permissions to complete the task.

Step 3: Install Stockfish

  • Install Stockfish using the apt package manager: sudo apt install stockfish -y
  • This will download and install the latest stable version of Stockfish available in Ubuntu's repository.

Step 4: Verify Stockfish Installation

  • Check if Stockfish is installed correctly by running: stockfish
  • If the installation is successful, you’ll see the Stockfish prompt (Stockfish 15.1 by the Stockfish developers) appear.
  • At the Stockfish prompt, you can test the server's computational strength by running the bench command, you should see the following:
Total time (ms) : 3892
Nodes searched  : 2593605
Nodes/second    : 666393

The bench command runs a built-in performance benchmark that evaluates the speed of Stockfish on your server. It provides information such as the number of nodes calculated per second (nps), which indicates the server's strength for chess analysis.

  • Review the output to get an idea of how well Stockfish performs on your server. Higher nps values indicate faster analysis capabilities.
  • Once done, exit Stockfish by typing: quit

Note: The apt package manager installs the stable version of Stockfish available in the Ubuntu repository. If you need the latest development version or want to customize Stockfish, you’ll need to build it from source. For most users, the version installed via apt will be sufficient.

With these steps, we have successfully set up a cloud server, installed Stockfish, and configured secure communication via SSH using PuTTY, allowing you to harness the power of a remote chess engine for high-performance analysis.

5. Creating a Proxy to Connect Stockfish to Chessbase

Chessbase requires an executable (.exe) file to connect to external engines. Since Stockfish runs on your Ubuntu server, a proxy is needed to bridge Chessbase and Stockfish. The provided Python script leverages plink.exe (installed as part of PuTTY) to establish an SSH connection to your server and relay commands between Chessbase and Stockfish.

Note: Before deciding to create my own proxy, I explored tools like Polyglot and other similar options to bridge Chessbase with Stockfish. However, after spending considerable time trying to make these tools work without success, I decided to build my own proxy from scratch. This approach allowed me to have full control over the setup and functionality, leading to a simpler, more customizable solution.

Step 1: Install Python

  1. Download Python:
  2. Run the Installer:
    • Double-click the downloaded file to start the installation process.
    • On the first screen, check the box labeled Add Python to PATH (this is important to run Python from the command line).
    • Click Install Now.
  3. Verify the Installation:
    • Open a command prompt and type: python --version
    • This should display the installed Python version (e.g., Python 3.x.x).
  4. Install pip (if not already installed): python -m ensurepip --upgrade

Python is a versatile and beginner-friendly programming language known for its simplicity, readability, and extensive library support. Widely used in fields like web development, data analysis, machine learning, and automation, Python's clean syntax makes it easy to write and test code quickly. Its cross-platform compatibility ensures it runs seamlessly on Windows, macOS, and Linux, making it ideal for projects involving remote servers. With libraries like subprocess, threading, and logging, Python simplifies complex tasks like managing SSH connections and handling parallel processes. Backed by an active community, Python is an excellent choice for automating workflows and bridging systems—like connecting Chessbase to a remote Stockfish instance—making it an indispensable tool for developers of all levels.

Step 2: Create the Proxy (remote_stockfish.py)

  • Create a file called named remote_stockfish.py with the following:
import subprocess
import threading
import sys
import os
import json
import logging
import queue
## Function to set up logging for the application
def setup_logging(config):
    """
    Configure logging for the application, only if logging is enabled in the config.

    Args:
        config (dict): Configuration dictionary loaded from config.json.
    """
    if config.get("logging_enabled", False):  # Check if logging is enabled in the configuration
        logging.basicConfig(
            filename="debug.log",  # Log file name
            level=logging.DEBUG,  # Log level (DEBUG includes detailed information)
            format="%(asctime)s - %(levelname)s - %(message)s"  # Format for log messages
        )
        logging.info("Logging initialized.")  # Log that logging has started
    else:
## If logging is disabled, suppress all log levels except CRITICAL
        logging.basicConfig(level=logging.CRITICAL)
## Function to load configuration from a JSON file
def load_config():
    """
    Load configuration from config.json located in the same directory as the script.

    Returns:
        dict: Loaded configuration data.
    """
    config_path = os.path.join(os.path.dirname(sys.argv[0]), "config.json")  # Get the config file path
    try:
        with open(config_path, "r") as file:  # Open the config file
            return json.load(file)  # Parse JSON and return as a dictionary
    except FileNotFoundError:
        logging.error(f"Configuration file '{config_path}' not found.")  # Log if the file is missing
        sys.exit(1)  # Exit the script with an error
    except json.JSONDecodeError as e:
        logging.error(f"Error parsing configuration file: {e}")  # Log if JSON is malformed
        sys.exit(1)
## Function to handle output from Stockfish and log it
def handle_output(process, output_queue, terminate_event):
    """
    Continuously read output from Stockfish (via Plink) and write it to stdout and logs.

    Args:
        process: The subprocess running Stockfish (via Plink).
        output_queue: Queue to store output lines for sequential processing.
        terminate_event: Event to signal when to stop reading output.
    """
    try:
        while not terminate_event.is_set():  # Loop until termination signal is received
            output = process.stdout.readline()  # Read a line from Stockfish's stdout
            if not output:  # Stop if no output is received
                break
            output = output.strip()  # Remove extra whitespace from the output
            logging.debug(f"Stockfish output: {output}")  # Log the output
            output_queue.put(output)  # Add the output to the queue for processing
            sys.stdout.write(output + "\n")  # Print the output to the console
            sys.stdout.flush()  # Ensure it appears immediately
    except Exception as e:
        logging.error(f"Error reading Stockfish output: {e}")  # Log any errors
## Function to wait for a specific marker in the output queue
def wait_for_marker(output_queue, marker):
    """
    Wait for a specific marker in the output queue.

    Args:
        output_queue: Queue containing Stockfish output.
        marker: The marker to wait for.
    """
    try:
        while True:  # Continuously check for the marker
            output = output_queue.get()  # Get the next output line from the queue
            if marker in output:  # If the marker is found in the output
                logging.debug(f"Marker '{marker}' found in output.")  # Log that the marker was found
                break  # Exit the loop
    except Exception as e:
        logging.error(f"Error waiting for marker '{marker}': {e}")  # Log any errors
## Main function to run the remote Stockfish engine
def run_remote_stockfish(config):
    """
    Starts the remote Stockfish engine using plink and processes input sequentially.

    Args:
        config: Dictionary containing configuration parameters.
    """
## Build paths to plink and the key file
    plink_path = os.path.abspath(config["plink_path"])
    key_file_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), config["key_file"]))
    host = config["host"]
    username = config["username"]
    remote_command = config["stockfish_command"]
## Build the plink command to run Stockfish remotely
    plink_command = [
        plink_path,
        "-batch",  # Run in batch mode (non-interactive)
        "-ssh",  # Use SSH for connection
        "-i", key_file_path,  # Path to the private key file
        f"{username}@{host}",  # Remote username and host
        remote_command  # Command to run Stockfish on the remote server
    ]
    logging.info(f"Plink command: {' '.join(plink_command)}")  # Log the full command

    try:
## Start the plink process
        process = subprocess.Popen(
            plink_command,
            stdin=subprocess.PIPE,  # Input to the process
            stdout=subprocess.PIPE,  # Output from the process
            stderr=subprocess.PIPE,  # Error output from the process
            text=True,  # Use text mode for input/output
            bufsize=1  # Line buffering
        )
        logging.info("Plink process started successfully.")  # Log success
## Initialize synchronization tools
        terminate_event = threading.Event()  # Event to signal thread termination
        output_queue = queue.Queue()  # Queue to hold Stockfish output
## Track if Stockfish is analyzing a position
        is_analyzing = False
        pending_command = None  # To store a queued command
## Start a thread to handle Stockfish output
        output_thread = threading.Thread(target=handle_output, args=(process, output_queue, terminate_event))
        output_thread.daemon = True  # Run the thread in the background
        output_thread.start()
## Main loop to process user input
        while True:
            try:
                user_input = input()  # Read user input from the console
                logging.debug(f"User input: {user_input.strip()}")  # Log the input

                if user_input.strip().lower() == "quit":  # Check for quit command
                    process.stdin.write(user_input + "\n")
                    process.stdin.flush()
                    terminate_event.set()  # Stop the output thread
                    break

                if is_analyzing and user_input.strip().lower() != "stop":
## If the engine is analyzing, send "stop" before a new command
                    logging.info("Engine is analyzing. Sending 'stop' command.")
                    pending_command = user_input
                    process.stdin.write("stop\n")
                    process.stdin.flush()
                    wait_for_marker(output_queue, "bestmove")  # Wait for bestmove response
                    is_analyzing = False
                    continue
## Send the command to Stockfish
                process.stdin.write(user_input + "\n")
                process.stdin.flush()
## Update the analyzing state based on the command
                if user_input.strip().startswith("go infinite"):
                    is_analyzing = True
                elif user_input.strip().lower() == "stop":
                    is_analyzing = False
## Handle specific markers for commands
                if user_input.strip() == "uci":
                    wait_for_marker(output_queue, "uciok")
                elif user_input.strip() == "isready":
                    wait_for_marker(output_queue, "readyok")
                elif "go" in user_input and "infinite" not in user_input:
                    wait_for_marker(output_queue, "bestmove")
## Process any pending command after "stop"
                if pending_command and not is_analyzing:
                    logging.info(f"Processing queued command: {pending_command.strip()}")
                    process.stdin.write(pending_command + "\n")
                    process.stdin.flush()
                    pending_command = None

            except EOFError:  # Handle end-of-file (e.g., when stdin closes)
                logging.warning("EOFError: stdin closed unexpectedly.")
                terminate_event.set()
                break
            except KeyboardInterrupt:  # Handle Ctrl+C
                logging.info("KeyboardInterrupt: Exiting...")
                terminate_event.set()
                break
            except Exception as e:  # Catch unexpected errors
                logging.error(f"Error processing user input: {e}")
## Wait for the output thread to finish
        output_thread.join()
## Terminate the plink process
        process.terminate()
        logging.info("Plink process terminated.")

    except Exception as e:
        logging.error(f"Error running Stockfish with Plink: {e}")  # Log any errors
    finally:
        logging.info("Remote Stockfish wrapper terminated.")  # Final cleanup log
## Main script entry point
if __name__ == "__main__":
    config = load_config()  # Load configuration
    setup_logging(config)  # Initialize logging
    logging.info("Starting remote Stockfish wrapper.")  # Log startup message
    run_remote_stockfish(config)  # Run the main function

Summary of the code:

  • Logging Setup: Configures logging based on the config.json file, writing debug information and errors to a debug.log file when enabled.
  • Configuration Management: Loads customizable settings from a config.json file, including server IP (host), username, private key path (key_file), plink.exe path, Stockfish command, and logging preferences.
  • Stockfish Output Handling: Reads and processes output from Stockfish via plink.exe, logs it, and uses a queue to manage sequential processing.
  • Marker Synchronization: Waits for specific markers (uciok, readyok, bestmove) in Stockfish's output to ensure proper command synchronization.
  • Command Processing: Accepts user input from the terminal, handles common commands like uci, isready, go infinite, and automatically sends stop if Stockfish is analyzing when new input is given.
  • Threading for Output: Runs Stockfish output handling in a separate thread, allowing real-time interaction and preventing blocking.
  • Plink Integration: Uses plink.exe to establish an SSH connection to the remote server, securely running Stockfish and relaying commands.
  • Error Handling: Catches and logs errors during configuration loading, Stockfish interaction, and terminal input.
  • Graceful Shutdown: Cleans up resources by terminating threads and the plink.exe process when the script exits or the quit command is issued.

Note: I’m not a professional Python developer, but this script has been tested and should work for the most part. If you encounter any issues, they might require some minor troubleshooting or adjustments based on your specific setup. Feel free to modify the script to better suit your needs!

Step 3: Set Up the Configuration File (config.json)

  • Create a file named config.json in the same directory as your Python script. This file allows you to configure the proxy without modifying the script.
{
  "host": "165.22.120.233",
  "username": "root",
  "key_file": "private.key.ppk",
  "plink_path": "C:\\Program Files\\PuTTY\\plink.exe",
  "stockfish_command": "stockfish",
  "logging_enabled": false
}
  • Replace "your_server_ip" with the IP address of your droplet.
  • Update "key_file" to point to the location of your private key (.ppk) file (this assume the same directory as the executable).
  • Ensure "plink_path" points to the correct location of plink.exe. By default, it is installed with PuTTY in: C:\\Program Files\\PuTTY\\plink.exe
  • Set "logging_enabled" to true if you want logs saved in a debug.log file.

JSON (JavaScript Object Notation) is a lightweight data format used for storing and exchanging information in a structured way. It is easy for humans to read and write, while also being simple for machines to parse and generate. JSON represents data as key-value pairs, arrays, or nested objects, making it highly versatile for configuration files, APIs, and data serialization.

Step 4: Test the Proxy Script

  • Ensure that the remote_stockfish.py, config.json and your private key is in the same directory.
  • Open a command prompt, navigate to the script’s directory, and run: python remote_stockfish.py
  • The script will:
    • Use plink.exe to connect to your server.
    • Start Stockfish remotely.
    • Relay commands between Chessbase and Stockfish.
    • Type in uci, isready to see the response. Type quit to exit stockfish.

Command Prompt Commands
The Command Prompt is a built-in tool in Windows that allows users to interact with their computer through text-based commands. It provides a direct way to perform tasks such as navigating directories, managing files, and running programs without using the graphical interface. Command Prompt is often used for troubleshooting, automation, and accessing advanced features not available through the standard Windows interface. It’s a powerful tool for both beginners and advanced users.

  • cd [folder name]: Change directory (move to a different folder).
  • cd ..: Go up one level to the parent folder.
  • cd \: Return to the root directory of the drive.
  • dir: List all files and folders in the current directory.
  • [drive letter]:: Switch to a different drive.
  • [file name]: Run an executable file in the current directory.
  • cls: Clear all text from the Command Prompt screen.
  • cd: Display the current folder you’re working in.

Step 5: Create an Executable with pyInstaller

PyInstaller is a powerful tool that allows you to convert Python scripts into standalone executables. These executables can run on systems without requiring a Python installation, making it easy to distribute and share your Python-based applications with others. PyInstaller packages your script, dependencies, and even configuration files into a single file or folder, ensuring everything needed to run the application is included.

  • Open a command prompt and run: pip install pyinstaller
  • Use pyInstaller to package the Python script into a standalone executable: pyinstaller --onefile remote_stockfish.py
  • After the process completes, you’ll find the executable (remote_stockfish.exe) in the dist folder.

Step 6: Verify and Configure the Executable

  • Ensure that remote_stockfish.exe and config.json are in the same directory. The script uses config.json for its settings, so this file must accompany the executable.
  • Test the executable by running: remote_stockfish.exe
  • If everything is set up correctly, the proxy will start, and Stockfish will run on your server via the executable.

6: Connecting the Remote Stockfish Engine to Chessbase

Now that your remote Stockfish engine is set up and accessible via the proxy script, the final step is to integrate it into Chessbase as a new engine. This allows Chessbase to communicate with the proxy, which in turn connects to Stockfish running on your server.

Step 1: Open Chessbase and Access the Engine Management

  • Launch Chessbase on your computer.
  • Navigate to the Engines menu and select Create UCI Engine.

Step 2: Add the Proxy Executable as a New Engine

  • In the Create UCI Engine dialog box:
    • Click Browse and locate the remote_stockfish.exe file you created using pyInstaller.
    • Select the .exe file and click Open.
    • Give the engine a name (e.g., "Stockfish (remote)").
  • Leave other settings at their default values and click OK.

Step 3: Test the Engine

  • Once added, test the engine by analyzing a position:
    • Open a chessboard or a game in Chessbase.
    • Go to the Engines tab and select the newly added "Remote Stockfish" engine.
    • Start the engine to see if it begins analyzing the position.

Step 4: Troubleshooting

If the engine doesn’t connect or analyze:

  • Ensure that your remote_stockfish.exe and config.json files are in the same directory.
  • Verify that your Python proxy script is properly configured (e.g., correct server IP, SSH key path, and plink.exe location).
  • Check that your server is running and Stockfish is accessible remotely.
  • Enable logging in config.json by setting "logging_enabled": true to check the debug.log file for errors.

Summary

In this guide, we’ve walked through the entire process of setting up and using a remote Stockfish engine in the cloud. Starting with creating a secure and cost-effective server on DigitalOcean, we installed Stockfish on Ubuntu and configured secure SSH communication using PuTTY. We then built a Python-based proxy to connect Chessbase to the remote engine, allowing seamless communication between your chess software and the powerful Stockfish engine hosted in the cloud. Finally, we integrated the proxy into Chessbase, enabling high-performance analysis without relying on local computing resources.
By following these steps, you now have a scalable and flexible setup that combines the power of cloud computing with the capabilities of Stockfish and Chessbase. Whether you’re analyzing games, exploring complex positions, or running multi-threaded analysis, this setup gives you the tools to take your chess studies to the next level. Have fun experimenting, learning, and improving your chess with this robust setup!

Note on Improving Security

The primary aim of this blog was to help you get up and running with a remote Stockfish setup. However, for enhanced security, you should consider implementing the following measures:

  • Create a Non-Root User to limit privileges for routine connections.
  • Whitelist Your IP to restrict server access to your own computer.
  • Disable Password Authentication to enforce key-based SSH logins.
  • Change the Default SSH Port to reduce the risk of automated attacks.
  • Enable a Firewall to allow only necessary ports, such as SSH.
  • Regularly Update Software to ensure the latest security patches are applied.
  • Monitor Access Logs to identify unauthorized login attempts.
  • Set Up Fail2Ban to block IPs with repeated failed login attempts.
  • Use Strong Private Key Passphrases to protect your SSH keys.
  • Enable Two-Factor Authentication (2FA) for added SSH security.

If you're unsure how to implement the security measures mentioned above, you can use tools like ChatGPT or other AI assistants to guide you step-by-step. Simply ask for detailed instructions on topics like creating non-root users, configuring firewalls, or setting up Fail2Ban, and you'll receive tailored advice to help you secure your server effectively.

Important Note

Now that you’ve completed the setup, don’t forget to tear down your Droplet to avoid incurring unnecessary costs! Digital Ocean charges even if your Droplet is off.

I hope you enjoyed this blog and found it helpful! If you have any questions or need assistance, feel free to leave a comment in the section below.

Kind Regards,
Toan Hoang (@HollowLeaf)
Creator of Chessboard Magic