Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-sshd

A minimal SSH server implemented in Node.js, built with ssh2 and node-pty.

It provides a real interactive TTY shell and authenticates users using existing Linux authorized_keys files. Password authentication is intentionally not supported.

This project is designed for controlled environments such as internal tools, relay servers, or experimental SSH setups.


Features

  • SSH protocol server
  • Public key authentication only
  • Uses system authorized_keys
  • Real PTY shell (bash, etc.)
  • Optional UID/GID switch when running as root
  • No external user database required
  • Lightweight and easy to audit

Requirements

  • Linux environment
  • Node.js 18+ recommended
  • bash or compatible shell
  • Root privileges (optional, for UID/GID switching)

Installation

npm install ssh2 node-pty

Generate Host Key

An SSH host key is required.

ssh-keygen -t rsa -f host_rsa.key -N ""

By default, the server uses ./host_rsa.key.


Run

node node_sshd.js

Specify a port via environment variable:

PORT=22022 node node_sshd.js

Or via command-line argument:

node node_sshd.js 22022

Environment Variables

Name Description Default
PORT SSH listening port 22022
HOST_KEY Path to SSH host key ./host_rsa.key
AUTH_KEYS_ROOT User home root /home

Authentication

  • Public key authentication only
  • authorized_keys is resolved by username from:
/home/<username>/.ssh/authorized_keys
/root/.ssh/authorized_keys

This allows reuse of existing system SSH keys without duplication.


User Privileges

When the Node.js process is running as root and the user exists on the system:

id -u <username>
id -g <username>

The spawned PTY shell runs under that user's UID/GID.

If not running as root, the shell runs with the current process privileges.


Connect Example

ssh -p 22022 username@server-ip

Security Notes

This project is intended for restricted or internal environments.

The following features are intentionally not implemented:

  • Password authentication
  • SCP / SFTP
  • chroot or sandboxing
  • Session logging or auditing

If exposed to external networks, additional protections such as firewall rules, network isolation, and monitoring are strongly recommended.


Use Cases

  • SSH relay / jump server
  • Remote shell access for automation
  • macOS ↔ Linux tunneling
  • Custom SSH authentication prototypes
  • Temporary administrative access

License

MIT License


Contributing

Issues and pull requests are welcome.

This project intentionally focuses on minimal SSH server functionality and does not aim to replace OpenSSH.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages