npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-ssh-tunnel-advanced

v1.0.7

Published

Vite plugin to create SSH tunnels using system SSH for exposing local dev server remotely.

Readme

Vite Plugin SSH Tunnel Advanced

npm version MIT License

A Vite plugin to easily create an SSH tunnel from your local development server to a remote server. This allows you to expose your local Vite dev server (e.g., localhost:5173) on a port on a remote machine, making it accessible via the remote machine's IP or a domain pointing to it.

This plugin uses the system's ssh command-line utility to establish and manage the tunnel.

Features

  • Sets up an SSH reverse tunnel (ssh -R).
  • Uses a private key for authentication.
  • Automatically manages the tunnel lifecycle with the Vite dev server.
  • Gracefully closes the tunnel on server shutdown or process exit.
  • Configurable remote port.
  • Option to display a custom proxy URL in logs.
  • Colored logging for better readability.

Prerequisites

  • SSH Client: An SSH client must be installed and available in your system's PATH.
    • Linux/macOS: Usually available by default.
    • Windows: OpenSSH client is often included in modern Windows 10/11 versions or can be installed with Git for Windows.
  • SSH Server Configuration:
    • The remote SSH server must be configured to allow TCP forwarding. Ensure AllowTcpForwarding yes (or AllowTcpForwarding all) is set in your server's /etc/ssh/sshd_config.
    • For the remote port to be accessible from external networks (not just localhost on the remote server), GatewayPorts yes or GatewayPorts clientspecified must be set in /etc/ssh/sshd_config on the remote server. Restart the sshd service after changes.

Installation

npm install vite-plugin-ssh-tunnel-advanced --save-dev
# or
yarn add vite-plugin-ssh-tunnel-advanced --dev
# or
pnpm add vite-plugin-ssh-tunnel-advanced --save-dev

You might also need picocolors if not already present (though often a transitive dependency):

npm install picocolors

Usage

Import and add the plugin to your vite.config.js or vite.config.ts:

// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; // Example, use your framework plugin
import { sshTunnel } from 'vite-plugin-ssh-tunnel-advanced';

export default defineConfig({
  plugins: [
    react(),
    sshTunnel({
      host: 'your-remote-server.com',    // SSH server address
      username: 'ssh_user',               // SSH username
      privateKey: '~/.ssh/id_rsa_remote', // Path to your SSH private key
      remotePort: 9000,                   // Port to listen on the remote server
      // Optional: If you access the tunnel via a custom domain/proxy
      // proxyUrl: 'https://dev.your-app.com'
    }),
  ],
});

When you run your Vite dev server (npm run dev or yarn dev), the plugin will:

  1. Wait for the Vite server to start listening.
  2. Attempt to establish an SSH tunnel to your remote server.
  3. Traffic to your-remote-server.com:9000 (or your proxyUrl) will be forwarded to your local Vite dev server.

Configuration

The sshTunnel plugin accepts a configuration object with the following properties:

| Option | Type | Required | Default | Description | |--------------|----------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------| | host | string | Yes | | SSH server host address (e.g., 'example.com', '192.168.1.100'). | | username | string | Yes | | Username for the SSH connection (e.g., 'root', 'deploy_user'). | | privateKey | string | Yes | | Path to the SSH private key file. Can use ~ for home directory (e.g., '~/.ssh/id_rsa'). | | remotePort | number | No | 3000 | Remote port on the SSH server to listen on. Traffic to this port will be forwarded to the local Vite server. | | proxyUrl | string | No | | Optional URL to display in logs after tunnel setup. Useful if the remote server is accessed via a domain/proxy (e.g., 'https://dev.example.com'). |

How it Works

The plugin executes a command similar to this:

ssh -i "<privateKeyPath>" \
    -o ExitOnForwardFailure=yes \
    -o ServerAliveInterval=30 \
    -o ServerAliveCountMax=3 \
    -f -N -M -S "<socketPath>" \
    -R 0.0.0.0:<remotePort>:localhost:<localVitePort> \
    <username>@<host>
  • -R 0.0.0.0:<remotePort>:localhost:<localVitePort>: Sets up remote port forwarding.
  • -M -S <socketPath>: Uses SSH ControlMaster for managing the connection via a socket file, allowing for clean termination.
  • -f -N: Runs SSH in the background and prevents execution of remote commands.

Troubleshooting

  • "Private key file not found":
    • Ensure the path provided in privateKey is correct.
    • The plugin resolves ~ to your home directory.
    • Check file permissions.
  • "Failed to create SSH tunnel" / SSH stderr output:
    • Permission denied (publickey):
      • Verify the private key is authorized on the remote server for the specified user (i.e., its corresponding public key is in ~/.ssh/authorized_keys on the server).
      • Check permissions of your ~/.ssh directory (should be 700) and ~/.ssh/authorized_keys (should be 600 or 644) on the server.
    • Connection refused/timeout:
      • Ensure the host is correct and the SSH server is running and accessible.
      • Check firewalls (both local and on the remote server).
    • "Warning: remote port forwarding failed for listen port ":
      • The remotePort might already be in use on the remote server. Try a different port.
      • AllowTcpForwarding might be disabled on the server.
  • Tunnel connects, but proxyUrl or http://<host>:<remotePort> doesn't work:
    • Ensure GatewayPorts yes (or clientspecified) is set in the remote server's sshd_config if you want to access the remotePort from outside the remote server's localhost.
    • Check firewalls on the remote server that might be blocking incoming connections to remotePort.
    • If using a domain/proxy (like Nginx), ensure it's correctly configured to forward traffic to localhost:<remotePort> on the remote server.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues page.

License

This project is MIT licensed.