Part 1 of 10

    Getting Started with Claude Code

    Claude Code is Anthropic's command-line tool that brings AI-powered coding assistance directly to your terminal. Install it on your RamNode VPS and generate your first server hardening script.

    Terminal Native
    Filesystem Access
    Stateful Sessions
    1

    Prerequisites and Requirements

    Before starting, ensure you have the following:

    Server Requirements

    ResourceMinimumRecommended
    OSUbuntu 22.04+Ubuntu 24.04 LTS
    RAM1 GB2+ GB
    Node.jsv18v20 LTS

    Required Accounts

    • RamNode VPS: Any Cloud VPS plan running Ubuntu or Debian
    • Anthropic API Key: Get one at console.anthropic.com
    2

    Installing Claude Code

    Claude Code requires Node.js 18 or later. Here's the fastest path to a working installation:

    Install Node.js 20 LTS

    Install Node.js via NodeSource
    # Install Node.js 20 LTS via NodeSource
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    # Verify installation
    node --version  # Should show v20.x.x
    npm --version   # Should show 10.x.x

    Install Claude Code

    Install globally via npm
    npm install -g @anthropic-ai/claude-code

    Authenticate

    Run Claude Code for the first time to set up authentication:

    First run authentication
    claude

    You'll be prompted to enter your Anthropic API key. Claude Code stores this securely in ~/.claude/ and you won't need to enter it again.

    3

    Verifying the Installation

    Test that everything works correctly:

    Test Claude Code
    claude --version
    claude "Say hello and tell me what OS I'm running on"

    Claude Code will analyze your system and respond. You should see it identify your Linux distribution and kernel version.

    4

    Understanding How Claude Code Works

    Claude Code operates differently from ChatGPT or the Claude web interface. Key differences:

    It runs locally

    Claude Code executes on your machine, not in a browser sandbox. When you ask it to create a file, it creates a real file. When you ask it to run a command, it runs a real command.

    It has filesystem access

    Claude Code can read your project files, analyze logs, and write new files—all with your permission.

    It's conversational but stateful

    Each session maintains context. You can iteratively refine scripts, debug issues step-by-step, and build on previous outputs.

    It asks before acting

    By default, Claude Code will show you what it plans to do and ask for confirmation before executing commands or writing files.

    5

    Your First Task: Server Hardening Script

    Let's put Claude Code to work on something practical. Every new VPS should be hardened before production use. Instead of copying scripts from random blog posts, let's generate one tailored to your system.

    Starting the Conversation

    Start Claude Code session
    claude

    Once in the Claude Code session, describe what you need:

    "I just spun up a fresh Ubuntu 24.04 VPS. Generate a comprehensive server hardening script that:

    1. 1. Creates a non-root sudo user
    2. 2. Configures SSH (disable root login, change port, key-only auth)
    3. 3. Sets up UFW with sensible defaults
    4. 4. Installs and configures fail2ban
    5. 5. Enables automatic security updates
    6. 6. Sets up basic system auditing

    Make it idempotent so I can run it multiple times safely."

    What Happens Next

    Claude Code will:

    1. Analyze your request
    2. Generate a complete bash script
    3. Ask if you want to save it to a file
    4. Optionally offer to execute it (review carefully first)

    Example Generated Script

    server-hardening.sh
    #!/bin/bash
    # Server Hardening Script for Ubuntu 24.04
    # Generated by Claude Code
    
    set -euo pipefail
    
    # Configuration - modify these values
    NEW_USER="deploy"
    SSH_PORT="2222"
    
    # Colors for output
    RED='\033[0;31m'
    GREEN='\033[0;32m'
    NC='\033[0m'
    
    log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
    log_warn() { echo -e "${RED}[WARN]${NC} $1"; }
    
    # 1. Create non-root user with sudo access
    create_sudo_user() {
        if id "$NEW_USER" &>/dev/null; then
            log_info "User $NEW_USER already exists, skipping..."
            return 0
        fi
        
        log_info "Creating user $NEW_USER..."
        useradd -m -s /bin/bash -G sudo "$NEW_USER"
        
        # Copy SSH keys from root if they exist
        if [[ -f /root/.ssh/authorized_keys ]]; then
            mkdir -p /home/$NEW_USER/.ssh
            cp /root/.ssh/authorized_keys /home/$NEW_USER/.ssh/
            chown -R $NEW_USER:$NEW_USER /home/$NEW_USER/.ssh
            chmod 700 /home/$NEW_USER/.ssh
            chmod 600 /home/$NEW_USER/.ssh/authorized_keys
            log_info "Copied SSH keys to $NEW_USER"
        fi
    }
    
    # 2. Harden SSH configuration
    harden_ssh() {
        log_info "Hardening SSH configuration..."
        
        cat > /etc/ssh/sshd_config.d/hardening.conf << EOF
    Port $SSH_PORT
    PermitRootLogin no
    PasswordAuthentication no
    PubkeyAuthentication yes
    AuthenticationMethods publickey
    X11Forwarding no
    MaxAuthTries 3
    EOF
    
        if sshd -t; then
            systemctl reload sshd
            log_info "SSH hardened on port $SSH_PORT"
        else
            log_warn "SSH config validation failed, reverting..."
            rm /etc/ssh/sshd_config.d/hardening.conf
            return 1
        fi
    }
    
    # 3. Configure UFW firewall
    setup_firewall() {
        log_info "Configuring UFW firewall..."
        apt-get install -y ufw
        ufw --force reset
        ufw default deny incoming
        ufw default allow outgoing
        ufw allow "$SSH_PORT/tcp" comment 'SSH'
        ufw allow 80/tcp comment 'HTTP'
        ufw allow 443/tcp comment 'HTTPS'
        ufw --force enable
    }
    
    # 4. Install and configure fail2ban
    setup_fail2ban() {
        log_info "Setting up fail2ban..."
        apt-get install -y fail2ban
        
        cat > /etc/fail2ban/jail.local << EOF
    [DEFAULT]
    bantime = 1h
    findtime = 10m
    maxretry = 5
    
    [sshd]
    enabled = true
    port = $SSH_PORT
    maxretry = 3
    EOF
    
        systemctl enable fail2ban
        systemctl restart fail2ban
    }
    
    # Main execution
    main() {
        if [[ $EUID -ne 0 ]]; then
            echo "This script must be run as root"
            exit 1
        fi
        
        log_info "Starting server hardening..."
        apt-get update
        
        create_sudo_user
        harden_ssh
        setup_firewall
        setup_fail2ban
        
        log_info "Server hardening complete!"
    }
    
    main "$@"

    Refining the Output

    Claude Code shines in iterative refinement. Continue the conversation to add features:

    • SSH config validation before applying
    • A dry-run mode that shows what would change
    • Logging to /var/log/hardening.log
    6

    Cost Considerations

    Claude Code uses the Anthropic API, which charges per token. Here's what to expect:

    Task TypeApproximate Cost
    Simple script generation$0.01 - $0.05
    Complex multi-file project$0.10 - $0.50
    Extended debugging session$0.20 - $1.00

    Monitor your usage at console.anthropic.com.

    Tips for Minimizing Costs

    • Be specific upfront: Detailed initial prompts reduce back-and-forth
    • Use /clear between tasks: Resets context and avoids paying for irrelevant history
    • Set spending limits: Configure monthly limits in your Anthropic dashboard
    7

    Useful Commands Reference

    CommandDescription
    claudeStart interactive session
    claude "prompt"One-shot command
    claude -p "prompt"Print output only (no file writes)
    /helpShow available commands in session
    /clearClear conversation context
    /costShow token usage for current session
    Ctrl+CCancel current operation
    8

    Quick Troubleshooting

    "Command not found" after install

    Fix PATH issue
    # Ensure npm global bin is in PATH
    export PATH="$PATH:$(npm config get prefix)/bin"
    # Add to ~/.bashrc for persistence
    echo 'export PATH="$PATH:$(npm config get prefix)/bin"' >> ~/.bashrc

    API key issues

    Re-authenticate
    # Re-authenticate
    rm -rf ~/.claude
    claude

    Permission denied on scripts

    Make script executable
    chmod +x your-script.sh

    What's Next

    You've installed Claude Code and generated your first infrastructure script. In Part 2, we'll tackle something more ambitious: Automating OpenStack Infrastructure with Claude Code—generating Terraform configurations, managing security groups, and deploying multi-tier applications through natural language.

    Continue to Part 2