DEV Community

MT
MT

Posted on • Originally published at miantiao.me on

Demystifying SSH AI Chat: How It Works

Hello everyone, I'm MT, and today I'd like to share my recent project - SSH AI Chat.

SSH AI Chat

Project Introduction

SSH AI Chat is an AI chat application that you can connect to directly via SSH. Using it is incredibly simple:

ssh username@chat.aigc.ing
Enter fullscreen mode Exit fullscreen mode

Note⚠️: Replace username with your GitHub username

That's right, it's that simple! You don't need to install any client or open a browser. Just an SSH client is all you need to chat with AI.

As a developer with a strong interest in TUI applications, I've always felt that chatting in the terminal is a really cool concept. I was initially amazed by itter.sh - a social network you could access via SSH! This made me realize that SSH isn't just for connecting to servers; it can be used for many interesting things.

That's when I had this idea: how cool would it be to chat with AI via SSH! No software installation, no browser needed, just type ssh yourname@chat.aigc.ing in your terminal to start chatting.

Project Architecture

Core Technology Stack

  • SSH Server: Node.js + ssh2 module
  • UI Framework: React + Ink (for terminal rendering)
  • Database: PostgreSQL / PGLite (optional)
  • Cache: Redis / ioredis-mock (optional)
  • AI Integration: Vercel AI SDK

System Architecture Diagram

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   SSH Client    │    │   SSH Server    │    │   React App     │
│                 │    │                 │    │                 │
│  ssh username@  │───▶│  Node.js +      │───▶│  Ink UI +       │
│  chat.aigc.ing  │    │  ssh2           │    │  React Hooks    │
└─────────────────┘    └─────────────────┘    └─────────────────┘
                               │
                               ▼
                       ┌─────────────────┐
                       │   AI Services   │
                       │                 │
                       │  OpenAI API     │
                       │  Gemini API     │
                       │  DeepSeek API   │
                       └─────────────────┘
Enter fullscreen mode Exit fullscreen mode

Core Module Analysis

1. SSH Server Module

This is the core of the entire application, responsible for handling SSH connections and authentication. The system automatically handles key verification, GitHub public key authentication, login restrictions, and rate limiting.

2. Authentication System

The most clever design is the use of GitHub public key authentication. Users don't need to register; they can log in directly using their GitHub SSH keys. The system retrieves the user's GitHub public key for verification, caching it every 6 hours, making it both secure and efficient.

3. Terminal UI System

Using the Ink framework to render React components in the terminal. Imagine the React components you usually write, now rendering not in a browser but displaying in the terminal! It supports multilingual interfaces, real-time chat, history, model selection, and responsive layouts.

4. Chat System

Using Vercel AI SDK to handle AI conversations. When you type a message in the terminal, the system receives the message, loads conversation history, selects a model, displays streaming responses in real-time, and saves conversation records. It supports streaming responses, multi-model support, chain-of-thought display, and conversation history management.

Technical Challenges and Solutions

1. Terminal Rendering Challenges

The biggest challenge was implementing complex UI interfaces in the terminal. Using the Ink framework to render React components to the terminal and implementing a virtual PTY to handle terminal I/O. Displaying AI responses in Markdown in the terminal requires a dedicated worker process to handle the conversion to display bold, italic, and code blocks.

2. SSH Session Management

Managing multiple SSH sessions and states requires creating independent React application instances for each connection, using Context API to manage global state, and implementing session lifecycle management.

3. Real-time Streaming Responses

AI responses are streamed, and if the interface refreshes with every byte received, the terminal would freeze. Using Vercel AI SDK's streamText with throttled updates, refreshing every 300ms, ensures smooth performance without lag.

4. Flexibility in Data Storage

The project supports both PostgreSQL and PGLite databases, as well as Redis and in-memory caching, allowing the project to run independently or be deployed in production environments.

Interesting Design Details

1. GitHub Authentication

The coolest design! Users don't need to register; they can log in directly using their GitHub SSH keys, which is both convenient and secure.

2. Multi-model Support

Supports multiple AI models including DeepSeek-V3/DeepSeek-R1, Gemini-2.5-Flash/Gemini-2.5-Pro, including chain-of-thought display. It requires handling differences between various model APIs while providing a unified interface.

3. Internationalization Support

Complete i18n support, automatically detecting user language preferences through the LANG environment variable, with support for Chinese and English switching.

4. Keyboard Shortcuts

Ctrl+C to exit the application, N for new conversation, I to focus on input box, ? to view help. There are also some Easter egg features.

Development Insights

1. Possibilities of Terminal Applications

This project showed me the enormous potential of terminal applications. Through the Ink framework, we can implement complex interactive interfaces in the terminal.

2. Creative Uses of SSH

SSH is not just a remote management tool; it's also a powerful application platform. Through SSH, we can create cross-platform client applications without users needing to install any additional software.

3. Modern Technology Stack

Although this is a terminal application, we used the most modern technology stack: React, TypeScript, Vercel AI SDK, etc. This proves that terminal applications can also be "modern."

4. Pitfalls Encountered

SSH terminal compatibility issues, performance problems with streaming output, and performance challenges in conversation history management were all difficulties that needed to be overcome during development.

Future Outlook

Plans include supporting more AI models, including local models like Ollama, and supporting the MCP (Model Context Protocol) to allow users to extend functionality through plugins.

Conclusion

SSH AI Chat is an innovative project that integrates multiple technologies. It demonstrates:

  • The modern possibilities of terminal applications
  • Flexible applications of the SSH protocol
  • React's adaptability across different platforms
  • The popularization of AI technology

This project made me realize that technology isn't just for solving problems; it can also be fun. Combining SSH and AI created an unexpected experience.

I hope this project brings some inspiration to everyone, and let's explore the boundaries of technology together!

Try It Out

If you want to try it, you can use:

ssh username@chat.aigc.ing
Enter fullscreen mode Exit fullscreen mode

Project URL: https://github.com/ccbikai/ssh-ai-chat


If you have any questions or suggestions about this project, feel free to discuss them on GitHub. You're also welcome to Star this project - your support is my motivation to continue developing!

Top comments (0)