Repository: mafintosh/hyperssh Branch: master Commit: d8f9e2bd658e Files: 6 Total size: 6.8 KB Directory structure: gitextract_coapbr7j/ ├── .gitignore ├── LICENSE ├── README.md ├── client.js ├── fuse.js └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ package-lock.json node_modules ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2019 Mathias Buus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # hyperssh SSH and SSHFS over the [Hyperswarm DHT](https://github.com/holepunchto/hyperdht)! ## Installation ``` npm install -g hyperssh // ssh / fuse client stubs npm install -g hypertele // hyperswarm server proxy npm install -g hyper-cmd-utils // keygen utils ``` ## Usage ### Server On a server ```sh hyper-cmd-util-keygen --gen_seed -> SEED hypertele-server --seed SEED -l 22 -> PEER_KEY ``` This will start announcing the server on the DHT. ### Client On the client ```sh hyperssh -s ab01f... -u maf hyperssh -s ab01f... -u maf -i keypair.json ``` Read more about using identities here: https://github.com/prdn/hyper-cmd-docs/blob/main/identity.md SSHFS (mount a remove fs/folder via ssh) ```sh hyperssh-fuse -s ab01f... -u maf -m ~/mnt ``` Hyperswarm will do UDP holepunching under the hood, so even if your server is located on a home network it should be accessible. ### Windows RDP You can also use hyperssh with Windows RDP to remotely log in to your windows machines. On the server ```sh hypertele-server --seed SEED -l 3389 ``` On the client ```sh hyperssh --rdp -s ... ``` ## The hyper-cmd system hyperssh supports the hyper-cmd system! Identity management: https://github.com/prdn/hyper-cmd-docs/blob/main/identity.md Host resolution: https://github.com/prdn/hyper-cmd-docs/blob/main/resolve.md ## License MIT ================================================ FILE: client.js ================================================ #!/usr/bin/env node const { spawn } = require('child_process') const os = require('os') const HyperDHT = require('hyperdht') const net = require('net') const argv = require('minimist')(process.argv.slice(2)) const libNet = require('@hyper-cmd/lib-net') const libUtils = require('@hyper-cmd/lib-utils') const libKeys = require('@hyper-cmd/lib-keys') const connPiper = libNet.connPiper const helpMsg = 'Usage:\nhyperssh ?-i identity.json ?-s peer_key ?-u username ?-e ssh_command ?--rdp' if (argv.help) { console.log(helpMsg) process.exit(-1) } const conf = {} if (argv.s) { conf.peer = libUtils.resolveHostToKey([], argv.s) } if (!conf.keepAlive) { conf.keepAlive = 5000 } const peer = conf.peer if (!peer) { console.error('Error: peer is invalid') process.exit(-1) } const sshCommand = argv.e || '' function sshArgs (username, port) { return [ '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null', '-p', port, username + '@localhost' ].concat(sshCommand) } let keyPair = null if (argv.i) { keyPair = libUtils.resolveIdentity([], argv.i) if (!keyPair) { console.error('Error: identity file invalid') process.exit(-1) } keyPair = libKeys.parseKeyPair(keyPair) } const username = argv.u || os.userInfo().username const dht = new HyperDHT({ keyPair }) const proxy = net.createServer(c => { return connPiper(c, () => { const stream = dht.connect(Buffer.from(peer, 'hex')) stream.setKeepAlive(conf.keepAlive) return stream }, {}, {}) }) if (argv.rdp) { proxy.listen(3389, function () { console.log('Client listening on port 3389 (default RDP port)\nOpen your RDP client and connect to localhost') }) } else { proxy.listen(0, function () { const { port } = proxy.address() spawn('ssh', sshArgs(username, port), { stdio: 'inherit' }).once('exit', function (code) { process.exit(code) }) }) } process.once('SIGINT', () => { dht.destroy().then(() => { process.exit() }) }) ================================================ FILE: fuse.js ================================================ #!/usr/bin/env node const { spawn } = require('child_process') const os = require('os') const HyperDHT = require('hyperdht') const net = require('net') const argv = require('minimist')(process.argv.slice(2)) const libNet = require('@hyper-cmd/lib-net') const libUtils = require('@hyper-cmd/lib-utils') const libKeys = require('@hyper-cmd/lib-keys') const connPiper = libNet.connPiper const helpMsg = 'Usage:\nhyperssh-fuse ?-i identity.json ?-s peer_key ?-u username' if (argv.help) { console.log(helpMsg) process.exit(-1) } const conf = {} if (argv.s) { conf.peer = libUtils.resolveHostToKey([], argv.s) } const peer = conf.peer if (!peer) { console.error('Error: peer is invalid') process.exit(-1) } if (!argv.m) { console.error('Error: mount point invalid') } const mount = argv.m function sshArgs (username, port) { return [ username + '@localhost:', mount, '-p', port ] } let keyPair = null if (argv.i) { keyPair = libUtils.resolveIdentity([], argv.i) if (!keyPair) { console.error('Error: identity file invalid') process.exit(-1) } keyPair = libKeys.parseKeyPair(keyPair) } const username = argv.u || os.userInfo().username const dht = new HyperDHT({ keyPair }) const proxy = net.createServer(c => { return connPiper(c, () => { return dht.connect(Buffer.from(peer, 'hex')) }, {}, {}) }) proxy.listen(0, function () { const { port } = proxy.address() spawn('sshfs', sshArgs(username, port), { stdio: 'inherit' }).once('exit', function (code) { // stay alive }) }) process.once('SIGINT', () => { dht.destroy().then(() => { process.exit() }) }) ================================================ FILE: package.json ================================================ { "name": "hyperssh", "version": "5.0.4", "description": "Run SSH over Hyperswarm Beta!", "main": "index.js", "dependencies": { "@hyper-cmd/lib-net": "git+https://github.com/holepunchto/hyper-cmd-lib-net#v0.1.0", "@hyper-cmd/lib-keys": "git+https://github.com/holepunchto/hyper-cmd-lib-keys#v0.1.1", "@hyper-cmd/lib-utils": "git+https://github.com/holepunchto/hyper-cmd-lib-utils#v0.1.0", "hyperdht": "^6.20.1", "minimist": "1.2.8" }, "bin": { "hyperssh-fuse": "./fuse.js", "hyperssh": "./client.js" }, "repository": { "type": "git", "url": "https://github.com/mafintosh/hyperssh.git" }, "author": "Mathias Buus (@mafintosh)", "license": "MIT", "bugs": { "url": "https://github.com/mafintosh/hyperssh/issues" }, "homepage": "https://github.com/mafintosh/hyperssh" }