p2pshell
v0.0.10
Published
Spawn shells anywhere. Fully peer-to-peer, authenticated, and end to end encrypted
Downloads
2
Readme
p2pshell
Spawn shells anywhere. Fully peer-to-peer, authenticated, and end to end encrypted.
Install
npm i -g p2pshell
Usage
# Create keys
p2pshell-keygen [-f keyfile] [-c comment]
# Create a P2P server
p2pshell-server [-f keyfile] [--firewall filename] [--disable-firewall] [--protocol name]
# Connect to a P2P shell
p2pshell <server key or name> [-f keyfile]
# Local tunnel that forwards to remote host
p2pshell <server key or name> -L [address:]port:host:hostport
# Copy files (download and upload)
p2pshell-copy <[@host:]source> <[@host:]target> [-f keyfile]
Use --help
with any command for more information, for example p2pshell-server --help
.
First steps
Keys are automatically created with a default filename on first run.
Otherwise, you can first do:
p2pshell-keygen
Just connect to servers (they have to allow your public key):
p2pshell <server name or public key>
You could also create a server:
p2pshell-server
~/.p2pshell/authorized_peers
file will be empty, denying all connections by default.
Public keys can be added to the list to allow them in real-time.
Or you can use the --disable-firewall
flag to allow anyone to connect, useful for public services like game servers.
Known peers
There will be a file ~/.p2pshell/known_peers
.
Add named peers to the file like for example:
# <name> <public key>
home cdb7b7774c3d90547ce2038b51367dc4c96c42abf7c2e794bb5eb036ec7793cd
Now just p2pshell home
(it saves you writing the entire public key).
p2pshell-copy
Similar to scp
. It works with files, and with folders recursively.
For the next examples, remote_peer
is a name that can be added to the known_peers
file.
Upload a file from your desktop to a remote server:
p2pshell-copy ~/Desktop/file.txt @remote_peer:/root/file.txt
Download a file from a remote server to your desktop:
p2pshell-copy @remote_peer:/root/database.json ~/Desktop/db-backup.json
Note: in the future, the @
might be removed.
You can also use the public key of the server directly (without @
):
p2pshell-copy ~/Desktop/some-folder cdb7b7774c3d90547ce2038b51367dc4c96c42abf7c2e794bb5eb036ec7793cd:/root/backup-folder
Local tunnel
Client
It creates a local server, and every connection is forwarded to the remote host.
In this example, creates a local tunnel at 127.0.0.1:2020
(where you can connect to),
that later gets forwarded to a remote server which it connects to 127.0.0.1:3000
:
p2pshell remote_peer -L 127.0.0.1:2020:127.0.0.1:3000
Instead of remote_peer
you can use the server public key as well.
You can also pass several -L
to run multiple local servers that remote forwards:
p2pshell remote_peer -L 2020:127.0.0.1:3000 -L 2021:127.0.0.1:3000 -L 2022:127.0.0.1:3000
Server
By default, p2pshell-server
runs a server with full access, including forwarding to all hosts and ports.
You can run a server with restricted permissions to allow forwarding a specific host and port only.
Let's say you have a local project like a React app at http://127.0.0.1:3000/
,
you can create a restricted server to safely share this unique port like so:
p2pshell-server --protocol tunnel --tunnel-host 127.0.0.1 --tunnel-port 3000
Or if you want to allow multiple hosts, port range, etc:
p2pshell-server --protocol tunnel --tunnel-host 127.0.0.1 --tunnel-host 192.168.0.25 --tunnel-port 1080 --tunnel-port 3000 --tunnel-port 4100-4200
Clients trying to use any different hosts/ports are automatically disconnected.
Multiple keys
To have multiple servers, you need multiple keys.
Generate another key:
p2pshell-keygen -f ~/.p2pshell/my-server
Now create a new shell server:
p2pshell-server -f ~/.p2pshell/my-server --firewall ~/.p2pshell/my-server-firewall
The client also accepts -f
in case you need it.
Restrict server protocols
This is the list of server protocols:
shell
upload
download
tunnel
By default, all of them are enabled when running a server.
For example, you could limit it to shell only:p2pshell-server --protocol shell
Or only allow file upload and/or download:p2pshell-server --protocol upload --protocol download
Restrict to tunnel only:p2pshell-server --protocol tunnel
For example, if you only allow tunnel
, then any attempt from clients to shell
into the server will auto disconnect them.
License
MIT