Files
bare-operating-system/packages/bare-os-openssh/vendor/bare-ssh2/scripts/openssh-test-server

Local OpenSSH test server

Runs a minimal sshd on 127.0.0.1:2222 (configurable) with public-key authentication only. No Docker.

Requirements

  • OpenSSH server binary (sshd) on the machine.
    • macOS: enable “Remote Login” in System Settings (installs/enables sshd), or brew install openssh and set SSHD_BINARY to the Homebrew sshd.
    • Linux: openssh-server (Debian/Ubuntu: sudo apt install openssh-server).

Run

cd /path/to/bare-ssh2
chmod +x scripts/openssh-test-server/run.sh
./scripts/openssh-test-server/run.sh

Or from the repo root:

npm run openssh:test-server

Environment (optional):

Variable Default Meaning
OPENSSH_TEST_PORT 2222 TCP port
OPENSSH_TEST_LISTEN 127.0.0.1 Bind address
OPENSSH_TEST_RUNTIME scripts/openssh-test-server/runtime Keys + config directory
SSHD_BINARY (auto) Full path to sshd if not found

State is stored under scripts/openssh-test-server/runtime/ (gitignored): host key, client key, authorized_keys, sshd_config.

Connect

The server authenticates your current OS username using the generated client key:

KEY=scripts/openssh-test-server/runtime/client_ed25519
ssh -i "$KEY" -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$(id -un)@127.0.0.1"

bare-ssh2 example

const { readFileSync } = require('fs')
const { Client } = require('bare-ssh2')

const client = new Client()
client
  .on('ready', () => {
    client.exec('echo hello-from-server', (err, stream) => {
      if (err) throw err
      stream.on('close', () => client.end()).on('data', (d) => process.stdout.write(d))
    })
  })
  .connect({
    host: '127.0.0.1',
    port: 2222,
    username: require('os').userInfo().username,
    privateKey: readFileSync('scripts/openssh-test-server/runtime/client_ed25519'),
  })

Notes

  • Foreground only: the script runs sshd -D -e so logs go to the terminal; Ctrl+C stops it.
  • If sshd complains about permissions or PAM, try running from a normal user session and ensure StrictModes no in the generated config (the script sets this).
  • Some managed macOS profiles block custom sshd; use a Linux VM or Homebrew openssh in that case.