Deploy a CLI AI Coding Assistant on Ubuntu 24.04 and Securely Access Its Web UI

    This guide explains how to deploy an open-source CLI AI coding assistant on an Ubuntu 24.04 server, install Node.js 22 LTS with nvm, configure the tool with a cloud-hosted model through an OpenAI-compatible API, and access its web interface safely using an SSH local port tunnel. It also covers common installation and connection issues and the security reasons for keeping the service bound to localhost.

    1. Solution Overview and Architecture

    Running an AI coding assistant on a server is a common way for developers to improve day-to-day productivity. Compared with running it on a local machine, server deployment offers several clear advantages:

    • The service can stay online 24/7 and is not affected by local machine shutdowns or restarts.
    • The compute and network environment is more stable, which can reduce latency when interacting with model APIs.
    • Multiple team members can share the same configuration more easily.

    The deployment described in this article consists of four stages:

    1. Basic environment preparation: Prepare an Ubuntu 24.04 server that can be accessed from your local computer over SSH.
    2. Runtime installation: Install Node.js 22 LTS using a version manager.
    3. Tool deployment and model integration: Install the open-source AI assistant tool and connect it to a cloud provider’s large model inference API.
    4. Secure access: Because the service listens only on a local port by default, map the remote port to your local machine through an SSH tunnel instead of exposing the service directly to the public internet.

    This “remote deployment plus local tunnel access” pattern is a recommended security practice and a reusable methodology worth learning.

    2. Prerequisites

    Before you begin, confirm that the following requirements are met:

    • You have an Ubuntu 24.04 server with sudo privileges. For demonstration purposes, this article uses the root user; in production, create a regular user and elevate privileges with sudo.
    • Your local computer runs Windows, macOS, or Linux and has an SSH client installed.
    • The server has outbound internet access and can download software packages.
    • You have applied for a large model API key from a cloud provider’s platform. The key usually starts with a fixed prefix. Keep it secure and never commit it to a code repository.

    It is a good idea to update the system first so that the package sources are current:

    1. apt update && apt upgrade -y

    3. Install Node.js 22 LTS

    The AI assistant tool depends on a relatively recent Node.js runtime. Installing it with nvm (Node Version Manager) is recommended because it simplifies version management and future upgrades:

    1. # Install nvm
    2. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    3. source ~/.bashrc
    4. # Install Node.js and set the default version
    5. nvm install 22
    6. nvm alias default 22
    7. # Verify the installation
    8. node --version

    When the commands finish, node --version should output v22.x.x. Using nvm instead of the distribution’s default package source has several benefits: version switching is flexible, global packages can be installed without sudo, and the upgrade path is clear. If the server has slow access to GitHub, configure a mirror or proxy first.

    4. Deploy the AI Assistant Tool

    Install the target tool globally with npm:

    1. npm install -g <assistant-tool>@latest

    Two common issues may occur during installation:

    1. ENOTEMPTY error (directory not empty): This is usually caused by leftover files from a previous failed installation. Remove the residual directory, clean the npm cache, and try again:
    1. rm -rf ~/.npm-global/lib/node_modules/<assistant-tool>
    2. npm cache clean --force
    3. npm install -g <assistant-tool>@latest
    1. Deprecated warnings: These are normal dependency warnings and do not affect functionality. You can ignore them.

    After installation, verify the version number to confirm that the tool is available:

    1. <assistant-tool> --version

    5. Connect to a Large Model API

    Open-source assistant tools generally support custom model providers. Through the OpenAI-compatible protocol, you can connect to any inference service that implements this protocol. Run the interactive configuration command:

    1. <assistant-tool> config

    Complete the following steps as prompted by the wizard:

    1. Select Add a custom provider.
    2. Enter a provider name. You can choose your own, such as my-llm-provider.
    3. Enter the API address: the inference endpoint provided by the cloud provider’s platform. It is usually in the form https://<domain>/<version-path> and can be found in the API documentation.
    4. Enter the API key that you applied for.
    5. Select the model name: enter the identifier of the model you are connecting to. This article uses a lightweight Flash-series model, which offers fast responses and low invocation cost and is suitable for everyday coding Q&A.

    After configuration is complete, run a simple prompt as a connectivity test to confirm that the model returns results normally before you start using the assistant in practice.

    6. Securely Access the Web Interface Through an SSH Tunnel

    For security reasons, the tool’s web interface listens only on 127.0.0.1 by default, so it cannot be accessed directly from the public internet. The recommended approach is to use SSH local port forwarding to map the remote port to your local machine:

    1. ssh -L 18789:127.0.0.1:18789 user@your-server-ip

    Keep this SSH connection open, and then visit http://127.0.0.1:18789 in your local browser to open the assistant interface.

    This approach improves security in three ways:

    • The service is not exposed to the public internet, which significantly reduces the attack surface.
    • Data is transmitted through an encrypted SSH channel, which helps prevent man-in-the-middle eavesdropping.
    • No additional HTTPS certificate or reverse proxy is required, so implementation cost is low.

    If a team needs multi-user access, you can, after confirming that it is safe to do so, expose the service through an Nginx reverse proxy with HTTPS and access authentication. However, that goes beyond personal use and requires careful access control and log auditing.

    7. Troubleshooting

    • Authentication errors when calling the model: Check whether the API key is complete and unexpired, and whether the API address matches the platform to which the key belongs.
    • Connection timeouts: Confirm that the server has normal outbound network access. Some cloud environments require outbound rules or a proxy.
    • The interface is unreachable after the tunnel disconnects: When the SSH session ends, port forwarding stops working. Re-establish the connection. You can also use autossh to reconnect automatically.
    • Global command not found: This usually means the npm global directory is not in PATH. Run npm config get prefix to check the path and add it to your environment variables.

    8. Conclusion

    This article has walked through the complete process of deploying an open-source AI coding assistant on Ubuntu 24.04, connecting it to a cloud provider’s large model API, and securely accessing it through an SSH tunnel. The key points are using nvm to manage the Node.js runtime, connecting to a custom model provider through the OpenAI-compatible protocol, and following the “local listening plus tunnel access” secure deployment pattern. Once you understand this method, you can adapt it to any tool that supports custom providers and build your own AI workspace flexibly.