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 🙏

© 2024 – Pkg Stats / Ryan Hefner

forward-ssh

v1.1.1

Published

一个ssh 端口前向转发的工具,正向代理,反向代理

Downloads

8

Readme

SSH 隧道使用指南

此模块使用 ssh2 模块来创建 SSH 隧道,并通过反向端口转发来将本地服务映射到远程服务器。本指南将带您了解如何设置并使用此项目来实现远程服务的隧道连接。

1. 项目介绍

该模块使用 ssh2 模块的 Tunnel 类来创建 SSH 隧道,允许用户通过私钥文件连接到远程服务器,并设置反向端口转发。

主要功能:

  • 连接到远程服务器
  • 设置反向端口转发
  • 使用 SSH 隧道将本地端口映射到远程服务器

2. 前提条件

在使用此代码之前,请确保您具备以下条件:

  • Node.js 和 npm 已正确安装。
  • 您已经在本地生成了 SSH 密钥对。
  • 您可以通过 SSH 访问远程服务器。

3. 安装依赖

在项目目录中,运行以下命令以安装必要的依赖包:

npm install forward-ssh

功能

基于ssh2 的主机的反向代理和正向代理

实现方式

const { Tunnel } = require(".");
const os = require("os")
const path = require("path")
const fs = require("fs")

async function test(params) {
    // 远程服务器配置
    /**
     * @type {import("ssh2").ConnectConfig}
     */
    const remoteServer = {
        host: '127.0.0.1',
        port: 2233, // 默认SSH端口
        username: 'hwx',
        privateKey: fs.readFileSync(path.join(os.homedir(), "\\.ssh\\id_rsa")).toString() // 本地私钥文件路径
    };

    let t = await new Tunnel(remoteServer).onready();
    await t.connect({
        srcHost: "127.0.0.1", // 本地监听地址
        srcPort: 8888,  // 本地监听端口
        remoteHost: "127.0.0.1", //ssh 机器对应的服务的端口位置
        remotePort: 3009 //ssh 机器对应的服务的端口位置
    })
    // 本地地址 127.0.0.1:8888 将映射到远程服务器上的端口 3009。
    await t.forwardIn({
        remoteHost: "127.0.0.1",
         remotePort: 3000,
        srcHost: "127.0.0.1",
         srcPort: 8080
    })
    // 远程服务器地址 127.0.0.1:3000 将映射到本地的 127.0.0.1:8080

}

test()

配置 SSH 反向代理全局绑定

本指南将帮助您配置 SSH 服务,以便允许反向代理(Reverse SSH Port Forwarding)在远程服务器上监听所有地址(0.0.0.0),从而使外部设备能够通过指定端口访问您的服务。

1. 修改 sshd_config 配置

SSH 服务的配置文件通常位于 /etc/ssh/sshd_config,您需要编辑此文件以允许 SSH 反向代理绑定到所有 IP 地址。

步骤

  1. 使用管理员权限打开 sshd_config 文件:
    sudo nano /etc/ssh/sshd_config
  2. 允许反向代理绑定到 0.0.0.0,而不仅限于 127.0.0.1 GatewayPorts yes
  3. 重启ssh 服务以应用更改 sudo systemctl restart sshd