Deploying an AI Coding Application on Ubuntu 24.04 LTS with Secure SSH Access

    This guide explains how to deploy an AI coding application on an Ubuntu 24.04 LTS server and connect it to an API-compatible model service. It covers user and Node.js setup, application installation and model configuration, loopback-only startup, encrypted access through SSH local port forwarding, systemd user services, log management, and security hardening. Readers will learn how to validate each layer, troubleshoot common failures, and keep the application running without exposing its web port to the public internet.

    1. Solution Overview

    This article explains how to deploy an AI coding application on an Ubuntu 24.04 LTS server and connect it to a model service that is compatible with a standard API interface. The application runs on the server, and you access it from a browser on your local computer. The web port listens only on the server’s loopback address, 127.0.0.1, and is accessed through encrypted SSH local port forwarding. No management port is exposed to the public internet.

    The complete workflow has seven steps:

    1. Prepare a regular server user and remote login.
    2. Install the Node.js runtime.
    3. Install the AI coding application.
    4. Configure the model service address and access key.
    5. Start the application and confirm its listening address.
    6. Establish an SSH tunnel to access the web page.
    7. Configure process supervision, logging, and security policies.

    This article assumes Ubuntu 24.04 LTS. Package sources and commands may differ on other distributions, so adjust them as needed. Model requests are initiated by the server, so the server must be able to reach the model service’s external endpoint.

    2. Before You Begin

    2.1 Server Requirements

    • At least 2 CPU cores.
    • At least 2 GB of available memory.
    • At least 10 GB of remaining disk space is recommended. Dependencies and logs will continue to consume space.
    • Access to the model service endpoint.
    • A regular user, referred to in this article as devuser, with the ability to use sudo for temporary privilege escalation.

    For a long-running environment, do not operate directly as the root account. Create a regular user with the following commands:

    1. sudo adduser devuser
    2. sudo usermod -aG sudo devuser

    Use this regular user for all subsequent operations. Use sudo only when installing system-level packages.

    2.2 Model Service Credentials

    Create an access key in the model service console and follow these precautions:

    • Do not write the key into a public code repository.
    • Do not paste the key into screenshots, tickets, or chat records.
    • Do not expose the key in frontend pages.
    • Create separate keys for development, testing, and production environments.
    • If a key is leaked, revoke it in the console immediately and generate a new one.

    2.3 Local Environment

    Your local computer must meet the following requirements:

    • An SSH client that supports port forwarding. Linux and macOS include OpenSSH. Windows 10 and later can enable the OpenSSH client.
    • A modern browser.
    • Local port 3000 must be free. See Section 8 for how to check it.

    3. Install the Node.js Runtime

    The Node.js version in the Ubuntu software repository may be lower than the application requires. Installing an LTS version with nvm is recommended. nvm installs into the user’s home directory and does not require root privileges.

    Check the latest version in the official nvm repository at https://github.com/nvm-sh/nvm and replace the version number in the command below. This article uses v0.40.3 as an example.

    1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

    The install script modifies ~/.bashrc. If you prefer to be more cautious, download the script first, inspect it with less, and run it only after confirming the contents.

    After installation, run the following commands in order:

    1. source ~/.bashrc
    2. nvm install --lts
    3. nvm alias default lts/*
    4. node -v
    5. npm -v
    6. which node

    The output of which node should be under ~/.nvm/versions/node/. If it shows /usr/bin/node, the system version is taking precedence. Reopen the terminal or run hash -r and check again.

    The application’s minimum Node.js version requirement is stated in its official documentation. If node -v is lower than that requirement, install a specific major version with a command such as nvm install 22.

    4. Install the AI Coding Application

    The following example uses example-ai-coder as the package name. Replace it with the npm package name provided in the application’s official documentation.

    1. npm install --global example-ai-coder@latest
    2. example-ai-coder --version
    3. which example-ai-coder

    If the version command returns output, the command-line entry has been added to the current user’s PATH. Because Node.js is installed in the user directory through nvm, global packages also belong to the current user, so sudo is usually not required. Avoid sudo npm install -g; otherwise, the global directory will be owned by root, and later upgrades may encounter permission conflicts.

    Common Installation Issues

    4.1 Installation Failure Caused by Residual Files

    This issue is usually caused by an interrupted previous installation or an inconsistent cache. First confirm whether any residual process is running, then inspect the global installation directory:

    1. pgrep -af example-ai-coder
    2. ls -la "$(npm root -g)/example-ai-coder"

    If no process is running and the directory is confirmed to be a residual from a failed installation, move it to a backup location instead of deleting it directly:

    1. mv "$(npm root -g)/example-ai-coder" ~/example-ai-coder.bak.$(date +%F)
    2. npm cache verify
    3. npm install --global example-ai-coder@latest

    After confirming that the new version works correctly, manually delete the backup directory. Do not use recursive deletion on paths you are unsure about.

    4.2 Permission Errors

    If an EACCES error appears, first check where the current npm comes from:

    1. which npm

    If the output is /usr/bin/npm, the system Node.js is being used. Switch to the nvm-installed version and run the installation command again.

    4.3 Dependency Warnings

    Warnings such as deprecated or peer dependency messages during installation do not necessarily mean the installation failed. Focus on the exit status and the version command result:

    1. npm install --global example-ai-coder@latest; echo "exit: $?"
    2. example-ai-coder --version

    If the exit status is 0 and the version command returns normally, you can usually continue with the configuration.

    5. Configure the Model Service

    Run the interactive configuration wizard:

    1. example-ai-coder config

    The wizard generally asks for the following information:

    1. Service name: Any name that is easy to identify, such as default-model.
    2. Base URL: Copy the base URL of the compatible interface from the provider’s documentation. It usually contains only the version segment, for example https://api.example.com/v1. Do not enter the full request path, such as /chat/completions.
    3. Access key: Paste the key created earlier. The terminal does not echo characters while you type. This is normal security behavior.
    4. Model identifier: Use exactly the name shown in the provider’s console or documentation, including case, hyphens, and version suffixes.
    5. Default parameters: For the initial deployment, keep the provider’s recommended values. Changing multiple parameters at the same time makes troubleshooting harder.

    Before configuring, validate the base URL and key with curl. Use the command below and avoid curl -v, because verbose output shows the key in request headers:

    1. read -rsp "Enter model API key: " MODEL_API_KEY; echo
    2. curl -sS -o /dev/null -w "%{http_code}\n" \
    3. -H "Authorization: Bearer $MODEL_API_KEY" \
    4. https://api.example.com/v1/models

    Replace https://api.example.com/v1 with your actual base URL. The response codes mean the following:

    • 200: The URL and key are valid.
    • 401 or 403: The key is incorrect, expired, or lacks permissions.
    • 404: The base URL or path is incorrect.
    • 429: The request rate or quota has been exceeded.

    If the provider does not offer a /models endpoint, use a minimal request example from its documentation for validation.

    After configuration, if the application provides a test subcommand, run example-ai-coder test. Otherwise, send a short message in the web page to confirm that the model returns results correctly.

    6. Configuration Files and Key Protection

    The configuration file location is specified in the application’s official documentation. Common locations are ~/.config/<application-name> or ~/.<application-name>. Check both:

    1. ls -la ~/.config/example-ai-coder/ 2>/dev/null
    2. ls -la ~/.example-ai-coder/ 2>/dev/null

    After locating the configuration file, set its permissions so that only the owner can read and write it:

    1. chmod 600 ~/.config/example-ai-coder/config.json

    600 means only the file owner can read and write the file. Command output may contain local paths, so do not paste it directly into tickets or chat records.

    If the application supports reading the key from environment variables, do not write export MODEL_API_KEY=... into ~/.bashrc. The default permissions of ~/.bashrc are broad, and the key would remain in the file in plaintext. A safer approach is to write the key into an environment file with permissions set to 600 and load it through the systemd service described in Section 10. Also, do not pass the key to the application as a command-line argument, because tools such as ps may display process arguments.

    7. Start the Application and Confirm the Listening Address

    Start the application on the loopback address and a specified port:

    1. example-ai-coder start --host 127.0.0.1 --port 3000

    After startup, check the listening address and local access:

    1. ss -lntp | grep 3000
    2. curl -sS -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3000

    A normal result should show 127.0.0.1:3000. If it shows 0.0.0.0:3000 or *:3000, the service is open to all network interfaces. Stop the application immediately, correct the configuration, and continue. Do not make it directly externally visible through a reverse proxy, port mapping, or firewall port opening.

    If the application does not support specifying a listening address, check the official documentation for the binding address configuration option.

    The first startup may need to initialize the configuration directory or database, so a long startup time is normal. Check the logs first instead of repeatedly running the start command, which may cause a port conflict.

    8. Access the Web Page Through an SSH Tunnel

    The following examples assume:

    • The application on the server listens on port 3000.
    • The server address is server.example.
    • The login user is devuser.

    Run the following command on your local computer to establish the tunnel:

    1. ssh -N -o ExitOnForwardFailure=yes -L 127.0.0.1:3000:127.0.0.1:3000 devuser@server.example

    The parameters work as follows:

    • -N means no remote shell is opened; only forwarding is kept active.
    • ExitOnForwardFailure=yes means the command exits immediately if the local port cannot be bound, instead of failing silently.
    • 127.0.0.1:3000 means the forwarded port listens only on the local loopback address.

    Check locally whether the port is already in use:

    1. # Linux or macOS
    2. lsof -iTCP:3000 -sTCP:LISTEN
    1. # Windows PowerShell
    2. Get-NetTCPConnection -LocalPort 3000 -State Listen

    If port 3000 is already in use, use a different local port, such as 18080:

    1. ssh -N -o ExitOnForwardFailure=yes -L 127.0.0.1:18080:127.0.0.1:3000 devuser@server.example

    After the tunnel is established, open http://127.0.0.1:3000 in your local browser, or http://127.0.0.1:18080 if you changed the port. You can also verify from a local terminal:

    1. curl -sS -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3000

    If the tunnel cannot be established, add -v to view detailed logs. Closing the tunnel terminal also terminates forwarding.

    Security Boundaries

    • Do not change the application to listen on 0.0.0.0, and do not open public access to the application port.
    • An SSH tunnel does not replace the application’s own login authentication. If the web page has a default account or password, change it immediately after the first login.
    • The server firewall should allow only SSH. If ufw is not yet enabled, allow OpenSSH before enabling the firewall; otherwise, the current connection may be disconnected:
    1. sudo ufw allow OpenSSH
    2. sudo ufw default deny incoming
    3. sudo ufw enable
    4. sudo ufw status verbose

    The output should not contain an allow rule for port 3000.

    9. Troubleshooting Checklist

    Checking the following items in order can help locate the problem quickly.

    1. Is the application process running? pgrep -af example-ai-coder
    2. Is the service port listening? ss -lntp | grep 3000
    3. Can the server access it locally? curl -sS -I http://127.0.0.1:3000
    4. Is the runtime version correct? which node && node -v
    5. Is the tunnel still connected? Check whether the SSH terminal is still running. If necessary, reconnect with -v.
    6. Is the model API available? Run the curl test from Section 5 again.

    If the application runs as a systemd user service, view the logs:

    1. journalctl --user -u example-ai-coder -n 100 --no-pager

    You can also check the output in the startup terminal or the log file path specified in the application’s official documentation.

    Common symptoms can be evaluated as follows:

    • The page does not open: Run step 3 first. If the server cannot access it locally, the application itself has a problem. If the server can access it locally but the local browser still cannot open it, the problem is in the SSH tunnel or the local port.
    • Model requests fail: Refer to the HTTP status code meanings in Section 5. 401 and 403 point to the key, 404 points to the base URL or model identifier, and 429 points to rate or quota limits.
    • The application exits immediately after startup: Check the logs for configuration format errors, Node.js version mismatch, port conflicts, or directory permission issues. The browser’s “cannot connect” message only means the frontend is unreachable; it does not identify the specific failure point.

    10. Long-Term Operation Recommendations

    After validation, you can hand the application over to a systemd user service so that it restarts automatically after a crash. First get the absolute path of example-ai-coder:

    1. which example-ai-coder

    Create an environment file and set its permissions to 600:

    1. mkdir -p ~/.config/example-ai-coder
    2. read -rsp "Enter model API key: " KEY; echo
    3. printf 'MODEL_API_KEY=%s\n' "$KEY" > ~/.config/example-ai-coder/env
    4. chmod 600 ~/.config/example-ai-coder/env
    5. unset KEY

    Create the service file ~/.config/systemd/user/example-ai-coder.service, and replace the path in ExecStart with the absolute path obtained in the previous step:

    1. [Unit]
    2. Description=Example AI coder web service
    3. After=network-online.target
    4. [Service]
    5. Type=simple
    6. EnvironmentFile=%h/.config/example-ai-coder/env
    7. ExecStart=/home/devuser/.nvm/versions/node/vX.Y.Z/bin/example-ai-coder start --host 127.0.0.1 --port 3000
    8. Restart=on-failure
    9. RestartSec=5
    10. [Install]
    11. WantedBy=default.target

    If the start command runs in the background and returns immediately, use the foreground start option provided by the application and keep Type=simple.

    Enable and start the service:

    1. systemctl --user daemon-reload
    2. systemctl --user enable --now example-ai-coder
    3. sudo loginctl enable-linger devuser

    enable-linger allows the user service to keep running after you log out.

    Additional long-term recommendations:

    • Manage logs through journald, and set a retention limit in /etc/systemd/journald.conf. If the application writes separate log files, configure logrotate for them.
    • Regularly update Node.js and application dependencies, and follow security advisories.
    • Regularly rotate model service keys and update the environment file after changes.
    • Configure disk and memory monitoring for the server.
    • Back up the configuration directory, but backup files must also retain 600 permissions.
    • Keep the firewall allowing only SSH, and do not expose the application port to the public internet.

    By combining loopback-only listening with encrypted SSH forwarding, you can access the web interface without opening additional public ports. Start with a regular user and a minimal configuration to complete validation, then gradually add automatic startup, log management, and team collaboration features.