This is an old revision of the document!
Shellhub is an open source alternative to Dataplicity. Run the Shellhub host on a host computer then run the agents on the remotes.
Host
- if you are already running ssh on the host you'll need to create (or add to) a
.env.overridefileSHELLHUB_SSH_PORT=<SOMETHING_OTHER_THAN_22>- you'll use this port # when logging into the remotes via ssh cli e.g.
ssh -p <PORT_#> <USER>@<SSHID_FOR_REMOTE>@<HOST_IP_OR_NAME>
- directions for install (dev environment not necessary)
- for ssl add to
.env.override:
SHELLHUB_AUTO_SSL=true SHELLHUB_REDIRECT_TO_HTTPS=true SHELLHUB_DOMAIN=<your domain or subdomain without quotes>
autostart
Add a systemd service:
- create
/etc/systemd/system/shellhub.service:
[Unit] Description=ShellHub After=network.target [Service] User=root Type=simple WorkingDirectory=<DIRECTORY WHERE SHELLHUB ROOT LIVES> ExecStart=make start Restart=always [Install] WantedBy=multi-user.target
sudo systemctl enable shellhub.servicesudo systemctl start shellhub.service
Remote
- Shellhub provides a docker container for RPI and friends but our candidate was a riscv64 mangopi for which there was no suitable Docker container
- Instead we cloned the repo then build the agent from source
git clone -b v0.10.4 https://github.com/shellhub-io/shellhub.git shellhub sudo apt install golang cd shellhub/agent go build -ldflags "-X main.AgentVersion=v0.10.4"
- Format for the public/private keys must be
pemso ssh keys from standardssh-keygenwill not work. Instead do something like:ssh-keygen -t rsa -f key.pem -m pemwith-m pembeing the magic sauce (source).
Autostart of Agent
- add a script
startAgent.shto start the agent:
#!/bin/bash export SHELLHUB_TENANT_ID="TENANT_ID" export SHELLHUB_PRIVATE_KEY="PRIVATE KEY PATH AND FILENAME IN PEM FORMAT" export SHELLHUB_SERVER_ADDRESS="SHELLHUB SERVER ADDRESS" ./agent
sudo chmod 755 startAgent.sh- starting the script from the shell works fine but for some reason does not work with
systemdunless we change/bin/shto usebashinstead ofdashsudo dpkg-reconfigure dashand choosenowhen prompted
- create
/etc/systemd/system/shellhubAgent.service
[Unit] Description=ShellhubAgent After=network.target [Service] User=root Type=simple WorkingDirectory=FULL PATH WHERE AGENT AND STARTUP SCRIPT ARE LOCATED ExecStart=FULL PATH AND FILENAME OF STARTUP SCRIPT Restart=always [Install] WantedBy=multi-user.target
sudo systemctl enable shellhubAgent.servicesudo systemctl start shellhubAgent.service
Login with cert to remote (agent)
- local machine generate public/private key.
- it could be that any public/private key would work but docs suggest
ssh-keygen -t ed25519
- upload public key to web portal (public keys menu on LHS)
- login from local machine using private key:
ssh -p <PORT> -i <PRIVATE_KEY_PATH_AND_FILE> <USER>@<SSHID_FOR_REMOTE>@<HOST_IP_OR_NAME>
Disable Password login
This is not a built-in function for community edition it appears so as a workaround we can hack the code
- in
/pkg/agent/server/server.goeditfunc (s *Server) passwordHandler(so the first line of the method readsreturn false cd shellhub/agentgo build -ldflags "-X main.AgentVersion=<VERSION>"