How to Deploy a Coding Agent on a Home NAS Virtual Machine: From SSH Hardening to Always-On Operation
Over the past two years, coding agents that can read and write files, run commands, and call external tools on their own have become part of many developers' daily workflows. This guide walks through deploying such an agent inside a self-hosted environment built on a home NAS and a Linux virtual machine. It covers resource planning, choosing a server or minimal OS image, creating the VM, and hardening SSH so you never lock yourself out, followed by installing the agent as a non-root user, wiring up a model endpoint and permission policy, and running it as a persistent service. You will learn how to pick CPU, memory, and disk sizing, why bridged networking and static addressing matter, why the agent must run under a regular account, why tmux is used for always-on sessions, and how to back up and maintain the setup. Follow the steps in order to reach a minimal working loop, then layer on scheduled tasks, parallel work, and long-running operation.
Deploying a Coding Agent on a Home NAS Virtual Machine: From SSH Hardening to Always-On Operation
1. Introduction: Why Run a Coding Agent in a Self-Hosted Environment
Over the past couple of years, coding agents that can read and write files, run commands, and call external tools on their own have become part of many developers’ daily toolkits. A lot of people start by trying an official web app or cloud service, but in real use several practical problems tend to come up:
- Data boundaries: Code, configuration, or internal scripts uploaded to a third-party environment may fall under compliance and company-asset requirements.
- Session uptime: Agents often need to stay resident for long periods, for batch jobs, scheduled checks, or message-bot handoffs. Once your laptop shuts down, the session is gone.
- Remote access: From the office, from another city, or on a different network, you want to reliably reach your own working directory.
- System integration: You want the agent to work with document folders and code repositories inside your home network, or to receive tasks through a messaging channel.
A “home NAS + virtual machine” setup is a good fit for hosting this kind of service. A NAS is usually built to run 24/7 with low power draw, and once its virtualization suite is mature you can create an isolated Linux VM on the NAS — effectively a small server inside your home.
This guide uses a common command-line coding agent as the example; below it is referred to as the “coding agent” or “client.” The whole process works without a graphical interface, so it is well suited to server or minimal Linux images. The overall flow is:
Create a VM and install the OS → Enable remote login → Install the agent as a regular user → Configure the model endpoint and permission policy → Run it as a persistent service and maintain it
Before you start, it helps to read with a few common questions in mind:
- How do you harden SSH without locking yourself out?
- How should you size VM memory and disk?
- Why do always-on services usually run under tmux?
- Should you install a server image or a desktop image?
- Why must the agent run as a non-root user?
2. Resource Planning Before You Begin
After a VM is created, CPU and memory can usually be adjusted once it is powered off, but expanding disk is more troublesome. It is worth planning everything up front.
| Resource | Recommended | Planning Notes |
|---|---|---|
| CPU | 2 cores minimum, 4 cores more comfortable | The agent itself is usually light, but dependency installs, build/test runs, and package downloads use CPU |
| Memory | 4GB recommended, 8GB safer | The resident process typically uses a few hundred MB, but dependency installs, compilation, or large-project analysis can spike |
| System disk | At least 60GB, err on the larger side | The OS, runtimes, caches, logs, and workspace files all keep growing |
| Network | Prefer bridged mode with a static address | Makes it easy for other LAN devices to reach it at a fixed address and avoids SSH failures from IP changes |
| Account | A regular account dedicated to the agent | Do not mix it with your daily login account; follow the principle of least privilege |
| Time | Synced with the hardware clock, correct time zone | Prevents garbled logs and failures in API signature or token validation |
If the NAS is tight on memory, first check what the storage services, packages, and existing VMs are using. When running VMs on mechanical disks, consider disabling write caching on the VM disk, or at least avoid frequent hard power cuts, to reduce the risk of data corruption.
Virtualization suites differ between NAS vendors, so before you deploy it helps to confirm a few things:
| Feature | Common Differences | Recommendation |
|---|---|---|
| Bridged networking | Some suites require selecting the right physical NIC | If bridging is not possible, fall back to NAT, but you will need to configure port forwarding yourself |
| Snapshots | Some support online snapshots, others only offline ones | Create a snapshot before upgrades or SSH changes whenever possible |
| VNC/console | Some include web-based VNC, others need an add-on package | Confirm this in advance so you still have console access if you misconfigure SSH |
| Storage pool | RAID and SSD cache support vary | Prefer a volume with stronger redundancy |
3. Preparing the System Image: Prefer a Server or Minimal Image
To avoid conflicts between later commands and the install flow, this guide recommends a server or minimal image throughout rather than defaulting to a desktop image. The reason is simple: every step below is done from the terminal, and server images use fewer resources and are closer to a real server environment.
3.1 Download and Verify the Image
- Download the server or minimal ISO from the official channel of your target Linux distribution.
- Verify file integrity against the official checksum, such as SHA256, to make sure the image was not replaced or corrupted in transit.
- Upload the image to a shared folder on the NAS; during OS installation it needs to be mounted as a virtual optical drive or ISO file.
If space on the NAS is limited, prefer the minimal image. It usually ships without a full desktop, so it installs smaller and boots faster.
3.2 Create the Virtual Machine
Create a new VM in the NAS virtualization suite with these key settings:
- Type and image: Choose the Linux type and mount the server or minimal image you uploaded.
- Resource allocation: Fill in CPU, memory, and disk sizes according to the previous section.
- Network mode: Choose bridged so the VM sits on the same LAN as the NAS, making remote login easy later.
- Storage pool: Prefer a volume with stronger redundancy to reduce losses from a single-disk failure.
- Boot order: Set the optical drive first during installation, then switch to disk-first once the OS is installed.
3.3 Install the Operating System
A few options in the installer directly affect the experience later:
- Select the language and keyboard layout you are comfortable with, so you can read and troubleshoot error messages.
- Choose your time zone; after installation, confirm the time and sync status with
timedatectl. - When creating a regular user, set a strong password. This account will be both the login entry point and the identity the agent runs under, so make it different from your other website passwords.
- If the installer offers automatic security updates, enable them.
If you chose a server or minimal image, there is usually no graphical desktop after installation. In that case, use the VNC console or serial terminal provided by the virtualization suite, or log in over SSH after installation. Do not assume a desktop terminal exists on the system.
4. Enable Remote Login and Harden SSH
Remote login is the foundation for everything that follows. Use SSH throughout rather than relying on a graphical desktop. SSH login comes in two forms:
- Password login: You enter a username and password. The credentials travel over the network and can be sniffed or brute-forced.
- Key login: You generate a key pair locally, keep the private key on your machine, and place the public key on the server. The server verifies a signature at login, so no passphrase is transmitted. This is the safer default.
Many tutorials will tell you to disable password login straight away, but if you do it in the wrong order it is easy to lock yourself out. The correct approach is: configure your public key and confirm key login works first, then disable password login.
4.1 Install Basic Tools
Once you are in the system, switch to root, update the package sources, and install the basic tools. Install tmux at the same time, since it is needed for always-on operation later:
sudo -iapt updateapt install -y curl wget git vim tmux
If the package sources are slow to update, switch to a mainstream mirror for your region.
4.2 The Correct Order for SSH Hardening
Here is a lock-out-proof flow. The key point is: before disabling password authentication, confirm that key login works.
Step 1: Keep Password Authentication On for Now
Before editing the SSH config, confirm the current configuration allows password login, or that it has not already been disabled elsewhere:
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.baksshd -T | grep -E '^(passwordauthentication|pubkeyauthentication|permitrootlogin|allowusers)'
If the output shows passwordauthentication yes, you can continue. If it is already no and you have not set up a public key yet, temporarily change it back to yes from the VNC console, or add your public key manually from the console.
Step 2: Generate a Key Pair Locally
Run this on your own computer, not on the NAS or the VM:
ssh-keygen -t ed25519
Set a key passphrase when prompted. A passphrase raises the bar even further if the private key is ever leaked.
Step 3: Install the Public Key on the VM
Using password login, copy your local public key to the VM:
ssh-copy-id youruser@<vm-ip>
If ssh-copy-id is not available, copy the public key contents manually, then log into the VM and write them in:
mkdir -p ~/.sshchmod 700 ~/.sshnano ~/.ssh/authorized_keyschmod 600 ~/.ssh/authorized_keys
Paste your local public key into authorized_keys.
Step 4: Verify Key Login Works
Without closing the current session, open a new local terminal and run:
ssh -i ~/.ssh/id_ed25519 youruser@<vm-ip>
If you can also log in without -i, the default private key path is already working. You must confirm you can log in without entering your user password before moving on.
Step 5: Disable Password Authentication
After confirming key login works, edit the SSH config:
nano /etc/ssh/sshd_config
A recommended configuration:
PermitRootLogin noPasswordAuthentication noPubkeyAuthentication yesAllowUsers youruser
Then check the syntax and restart the service:
sshd -tsystemctl restart ssh
On RedHat-family distributions, the service may be named sshd:
systemctl restart sshd
Service names vary by distribution; confirm with:
systemctl list-units --type=service | grep ssh
Step 6: Double-Check and Have a Rescue Plan
After the change, do not close your current SSH session yet. Open a new terminal and test login. If it fails, restore the config from the original session:
cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_configsshd -tsystemctl restart ssh
If you have already disabled password login and have no working SSH session, you can only get in through the NAS virtualization console, VNC, serial, or rescue mode. Once in, temporarily restore password authentication, or add authorized_keys manually:
mkdir -p /home/youruser/.sshchmod 700 /home/youruser/.sshnano /home/youruser/.ssh/authorized_keyschmod 600 /home/youruser/.ssh/authorized_keyschown -R youruser:youruser /home/youruser/.ssh
If you are using the root account, the path is /root/.ssh/authorized_keys.
4.3 Network Boundary Protection
After hardening SSH, add some defense at the network boundary:
- On the NAS or router firewall, allow access to the SSH port from the LAN only.
- If external access is truly needed, connect through a VPN into your home network rather than exposing the SSH port directly to the public internet.
- Use
whoto see the current logged-in sessions.
At this point the remote login path is working. Everything that follows — installation and configuration — is done as the regular user youruser, with no root required.
5. Install the Coding Agent as a Regular User
5.1 Why Not Use root
The core capability of a coding agent is to read and write files and run commands from natural-language instructions. It cannot reliably distinguish a benign instruction from a prompt injection. An accidental instruction from you, hidden instructions in web content, or a third-party document can all be treated as a task to execute.
If the agent runs as root, a single mistake could rewrite system configuration, delete system directories, or even be used as a stepping stone for lateral movement inside the network. Running as a regular user means system files and data volumes are protected at the file-permission level, so the blast radius is confined to the authorized directories.
5.2 Install the Node.js Runtime
A coding agent is usually driven by a JavaScript runtime. Below is a user-level install of Node.js that needs no root. Distributions, CPU architectures, and version numbers vary, so use the currently supported version from the official source.
First, confirm your CPU architecture:
uname -m
Common mappings:
x86_64: chooselinux-x64aarch64orarm64: chooselinux-arm64
The commands below use x86_64 and a specific Node.js version as an example; substitute the real version and architecture:
cd ~curl -fsSLO https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz
After downloading, verify integrity. Get the SHA256 for the file from the official SHASUMS256.txt:
EXPECTED_SHA=$(curl -fsSL https://nodejs.org/dist/v22.14.0/SHASUMS256.txt | grep 'node-v22.14.0-linux-x64.tar.xz' | awk '{print $1}')echo "$EXPECTED_SHA node-v22.14.0-linux-x64.tar.xz" | sha256sum -c -
Once verified, extract:
tar -xJf node-v22.14.0-linux-x64.tar.xz -C ~echo 'export PATH=$HOME/node-v22.14.0-linux-x64/bin:$PATH' >> ~/.bashrcsource ~/.bashrcnode -v && npm -v
Note: do not use outdated Node.js versions, as they may be missing security patches.
5.3 Install the Coding Agent
The install method varies by version. Common options include a package manager or an official install script. To reduce risk, avoid the pipe-to-shell pattern of curl ... | bash. A safer approach is to download the script, review it, and then run it.
Option 1: Install via Package Manager
npm install -g @anthropic-ai/claude-code
After installing, verify the version:
claude --version
Option 2: Use the Official Install Script
If an official install script is available, download and review it first:
curl -fsSLO https://claude.ai/install.shnano install.shbash install.sh
Before using it, confirm the source is trustworthy, and pay particular attention to whether the script makes any unauthorized changes to system directories. For production or home-server environments, prefer the package manager, since it makes later upgrades and rollbacks easier.
5.4 Three Checks After Installation
- Path is effective: Open a new terminal and run
which claudeto confirm it points to the executable under your user directory. - Basic function: Run
claudein a working directory to enter the interactive interface, and try a read-only question such as “list the files in the current directory.” - Authorization mechanism: The first run may ask to trust the current directory and to configure the model endpoint. This shows that the agent has an access boundary per working directory, so review and approve each one deliberately.
6. Configure the Model Endpoint and Permission Policy
6.1 Configure the Model Endpoint
The “brain” of a coding agent is a large language model. Installing the client is only the first step; you must configure a callable model endpoint before it can actually work. Possible sources include:
- Official subscription service: suitable for individual developers.
- Third-party model platforms or self-hosted inference services that are API-compatible: suitable for unified billing, keeping data inside your network, or calling domestic models.
- An internal enterprise model gateway: suitable for centrally managing model access for a team.
Configuration is usually done through environment variables. To keep secrets out of your shell history, create a config file in an editor rather than writing secret-bearing content with echo or cat:
mkdir -p ~/.config/claudechmod 700 ~/.config/claudenano ~/.config/claude/env
Write something like the following into the file:
export ANTHROPIC_BASE_URL="https://your-endpoint.example/api"export ANTHROPIC_AUTH_TOKEN="your-token"
After saving, set strict permissions and load it:
chmod 600 ~/.config/claude/envecho 'source ~/.config/claude/env' >> ~/.bashrcsource ~/.config/claude/env
The base URL and token field names may differ slightly by platform; follow the documentation of the platform you are connecting to. ANTHROPIC_AUTH_TOKEN is not a Windows system path, but a secret variable name agreed on by the client.
For security:
- Keep the secret only in a file with 600 permissions, and never put it in any repository you commit to.
- Do not use commands like
historyto echo back secret-bearing history. - On shared devices, avoid pasting the secret into chat tools or command history.
- Rotate the secret periodically, especially if the device has been handled by multiple people or the logs may be viewed by others.
6.2 Directories and Permissions: Give the Agent a Workspace
Set up a dedicated workspace, isolated from system files and media:
sudo mkdir -p /data/workspacesudo chown youruser:youruser /data/workspacecd /data/workspace
In the interactive interface, use /permissions or a similar command to manage the allow/deny tool lists; use /status to view the current account and model connection status. Command names may differ by version, so follow your client’s current version. The principle is “deny by default, allow as needed”:
- Read-only operations (listing directories, viewing files): allow directly.
- Write operations (creating, modifying files): restrict to authorized directories.
- Network operations (fetching pages, calling APIs): allow separately when you need connectivity.
- Dangerous operations (deletion, formatting, changing system config): keep manual confirmation on at all times.
6.3 Resuming Sessions and Switching Contexts
Long tasks often span several days, and using the following well reduces repeated effort:
- Resume sessions: use
claude --continueto resume the most recent session, andclaude --resumeto pick a session to resume from history. - Maintain project notes: create a
CLAUDE.mdat the project root describing the structure, build commands, and coding conventions. Many clients read it automatically, which makes output fit the project’s habits better. - Custom commands: put common code-review checklists or commit-message conventions into Markdown files under
.claude/commands/and call them quickly with/. Support varies by version. - Parallel tasks: if you need to handle multiple subtasks in parallel, the reliable approach is to open several tmux windows or several SSH sessions, each pointing at a different workspace. Some versions may offer multi-agent, plan mode, or code-review commands such as
/plan,/code-review, andagents, but command names and features change by version; follow your client’s current version and the official docs. - Quick model switching: type
/modelin the session to switch models. Use a lighter model for simple tasks to save cost, and switch to a stronger model for complex reasoning.
7. Always-On Operation, Backup, and Maintenance
7.1 Configure a User-Level Persistent Service
When a remote session disconnects, foreground processes are usually terminated. So the agent needs to run in a persistent session. A common approach is to use tmux and register it as a user-level systemd service.
First confirm tmux is installed:
sudo apt install -y tmuxtmux -V
Then allow the user’s persistent processes to survive logout:
loginctl enable-linger yourusermkdir -p ~/.config/systemd/usernano ~/.config/systemd/user/agent-tui.service
Write the following:
[Unit]Description=Home Lab Coding Agent (tmux wrapper)After=network-online.target[Service]Type=forkingExecStart=/usr/bin/tmux new-session -d -s agent -c /data/workspace "claude --continue"ExecStop=/usr/bin/tmux kill-session -t agentRestart=on-failureRestartSec=10[Install]WantedBy=default.target
Then enable the service:
systemctl --user daemon-reloadsystemctl --user enable --now agent-tui
Check the service status and tmux session:
systemctl --user status agent-tuitmux ls
To enter the agent interface, run:
tmux attach -t agent
If there is no prior session to resume, change claude --continue in ExecStart to claude to launch the interactive interface directly:
ExecStart=/usr/bin/tmux new-session -d -s agent -c /data/workspace "claude"
If your client version provides scheduled-task tools such as CronCreate, CronList, or CronDelete, you can use them for lightweight periodic tasks like log cleanup or dependency-update checks. Tool names and availability vary by version; follow the official docs. For heavy work that calls the model or processes files in bulk, avoid the NAS backup window to prevent disk I/O contention.
7.2 Backup Strategy
- Regular snapshots: before each upgrade or major config change, create a VM snapshot so you can roll back quickly if something goes wrong.
- Watch storage health: if the NAS supports S.M.A.R.T. monitoring, enable it, keep an eye on disk health, and replace suspect disks ahead of time.
- Back up the workspace separately: the agent itself can be reinstalled anytime. What is truly irreplaceable is the code and documents in the authorized directories, so back those up separately using a “local + off-site” approach.
7.3 Upgrades and Maintenance
If you installed via npm, you can try upgrading the client:
npm update -g @anthropic-ai/claude-code
If your version has a self-check command such as claude doctor, run it to check for installation and environment issues. Commands vary by version; if the command does not exist, refer to the official docs.
Before upgrading, read the release notes and pay attention to changes in the permission model, config format, and command names. If an upgrade fails, install a specified older version to roll back. The suspend or snapshot features in the virtualization suite can also restore the VM to its current state as a whole when needed.
8. Common Problems and How to Troubleshoot
| Symptom | Likely Cause | What to Do |
|---|---|---|
| SSH connection refused | Service not running, port blocked by firewall | In VNC, check systemctl status ssh and the firewall rules |
| Login drops immediately after connecting | sshd config syntax error | Check with sshd -t first, and keep the original session when editing |
| Cannot log in after disabling password login | Public key not working or wrong permissions | Enter via VNC and check ~/.ssh and authorized_keys permissions |
| Install or download times out | Package source or download URL points to an overseas server | Switch to a mirror, or set up an internal proxy for the VM |
| Agent reports no permission | Working directory ownership is wrong, or it is not in the allow list | Check the directory owner and authorize as needed with /permissions |
| Persistent service starts only tmux, no agent | ExecStart is missing the run command |
Change the command to tmux new-session ... "claude", or install tmux |
tmux ls shows no server running |
Service failed to start | Check systemctl --user status agent-tui and the journal logs |
| npm-type commands error out | A global directory was previously used as root | Fix ownership of user directories such as ~/.npm |
One principle helps when troubleshooting: locate the layer first, then the cause. For example, if remote login fails, work out in order whether it is “network unreachable,” “service not running,” or “authentication rejected” — far more efficient than reinstalling the system outright.
9. Security Hardening and a Routine Maintenance Checklist
- Back up before changing SSH: back up
/etc/ssh/sshd_configbefore editing, and check syntax withsshd -t. - Verify with a second session: after changing the SSH config, keep the current session open and test login from a new terminal.
- Run identity: do not run the agent as root; when possible, put it in a container that mounts only the authorized directories.
- Remote access: keep it LAN-only, or connect via VPN; do not map the port to the public internet.
- Key management: rotate keys periodically, set the private key to 600, and never commit it to a repo or paste it into chat logs.
- Tighten permissions: keep manual confirmation on for the long term, and allow only the tools that are genuinely needed.
- Auditability: retain session records and operation logs so you can trace what happened after the fact.
- Watch inputs: code, web pages, and documents from outside may contain prompt injections; be careful before executing.
- Routine checks: each week, check free disk space, VM resource usage, service health, and recent logs.
10. Conclusion
Deploying a coding agent is essentially setting up an automated work environment in your home network — one that “listens to instructions and takes action.” It ties together the fundamentals of creating a VM, remote login, permission isolation, service hosting, and backup maintenance.
As long as you follow three principles — least privilege, network isolation, and rollback capability — even an occasional mistake by the agent will be contained within a manageable scope.
Work through the steps in order and get the minimal loop running first: you can log in, have a conversation, and change files. Then gradually add plan mode, parallel tasks, and always-on operation, so this environment becomes a real part of your daily workflow.
