Skip to content

Automatically sets up an passwordless ssh connection over tor on your device at boot, so that you can always access your device from anywhere in the world, with a single command.

License

Notifications You must be signed in to change notification settings

HiveMinds/bash-ssh-over-tor

Repository files navigation

Sets up tor over SSH

Ensures you can access your computer from anywhere in the world with a single command. See why you need this, and how it works here.

Terminology

Since you SSH from one computer (Leader) into another (Follower):

Leader - The pc that you use to control the server. Follower - The pc that follows the orders you give from the Leader.

Getting started

You can use this repository in 2 ways:

  • Run it once on the Leader (requires (local) ssh access from Leader into Follower)
  • Run it once on the Follower and once on the Leader (Requires (physically) copying the onion domain and private key from Leader into ~~ Leader).~~ (Currently not supported.)

On Follower

To get the local ip address of the Follower device, type:

hostname -I

on it. Which outputs something like:15.14.3.42. Then type:

whoami

to get the Ubuntu username of the Follower, which outputs something like: somename.

git clone https://github.com/HiveMinds/bash-ssh-over-tor.git
cd bash-ssh-over-tor
chmod +x install-dependencies.sh
./install-dependencies.sh

chmod +x src/main.sh
src/main.sh --follower

Run Once on Leader

Open the terminal on the Leader machine and type:

chmod +x install-dependencies.sh
./install-dependencies.sh

chmod +x src/main.sh
src/main.sh \
--leader \
--follower-username somename \
--follower-local-ip 15.14.3.42 \
--follower-password the_ubuntu_password_of_the_ubuntu_username
  • Change these values with the output that you got at On Follower.
  • You can also omit the password with: --follower-password "" if you don't want to type it in plain text, then you will be prompted for the password.
  • If you have to access the device on a specific port, for example for a virtualbox system (HostIP=127.0.0.1, Host Port=2222, GuestIP=10.0.x.y, GuestPort=22), include --port 2222 where you change 2222 with the port number you need. If you don't include it, it defaults to 22. Note for ssh into virtualbox do: ssh -p 2222 <ubuntu username>@127.0.0.1.

That:

  • Generates a private and public key pair on the Leader machine (and adds it to the ssh-agent of the Leader machine).
  • Gets ssh access into Follower over WIFI/LAN.
  • Copies the public key from Leader into Follower.
  • Adds the copied public key to the authorised keys in the Follower machine. The output is the onion domain over which you can SSH into the Follower machine, like:
You can ssh into # oncethis server with command:
torsocks ssh follower_ubuntu_username@somelongoniondomainabcdefghikjlmnop.onion

You can now SSH from your Leader into your Follower machine and tell it what to do.

Run on Leader, then on Follower

Currently not supported, feel free to send a pull request.

Developer Information

Below is information for developers, e.g. how to use this as a dependency in other projects.

Install this bash dependency in other repo

  • In your other repo, include a file named: .gitmodules that includes:
[submodule "dependencies/bash-ssh-over-tor"]
 path = dependencies/bash-ssh-over-tor
 url = https://github.com/hiveminds/bash-ssh-over-tor
  • Create a file named install-dependencies.sh with content:
# Remove the submodules if they were still in the repo.
git rm --cached dependencies/bash-ssh-over-tor

# Remove and re-create the submodule directory.
rm -r "$SCRIPT_PATH/dependencies"/bash-ssh-over-tor
mkdir -p "$SCRIPT_PATH/dependencies"/bash-ssh-over-tor

# (Re) add the BATS submodules to this repository.
git submodule add --force https://github.com/hiveminds/bash-ssh-over-tor dependencies/bash-ssh-over-tor
  • Install the submodule with:
chmod +x install-dependencies.sh
./install-dependencies.sh

Call this bash dependency from other repo

After including this dependency you can use the functions in this module like:

#!/bin/bash

# Source the file containing the functions
source "$(dirname "${BASH_SOURCE[0]}")/src/main.sh"

# Naming conventions:
# server - The pc that you access and control.
# client - The pc that you use to control the server.

# Configure tor and ssh such that allows ssh access over tor.
configure_ssh_over_tor_at_boot

The 0 and 1 after the package name indicate whether it will update the package manager afterwards (0 = no update, 1 = package manager update after installation/removal)

Testing

Put your unit test files (with extension .bats) in folder: /test/

Developer Prerequisites

(Re)-install the required submodules with:

chmod +x install-dependencies.sh
./install-dependencies.sh

Install:

sudo gem install bats
sudo apt install bats -y
sudo gem install bashcov
sudo apt install shfmt -y
pre-commit install
pre-commit autoupdate

Pre-commit

Run pre-commit with:

pre-commit run --all

Tests

Run the tests with:

bats test

If you want to run particular tests, you could use the test.sh file:

chmod +x test.sh
./test.sh

Code coverage

bashcov bats test

How to help

  • Include bash code coverage in GitLab CI.
  • Add additional (relevant) pre-commit hooks.
  • Develop Bash documentation checks here, and add them to this pre-commit.

About

Automatically sets up an passwordless ssh connection over tor on your device at boot, so that you can always access your device from anywhere in the world, with a single command.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published