Last active
September 2, 2019 01:18
-
-
Save lmlsna/a4572d5b0089af7862250ac9c71cd66f to your computer and use it in GitHub Desktop.
Setup a tor hidden service for SSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set hidden service directory | |
# | |
hsdir=/var/lib/tor/sshd | |
# Add hidden service config to /etc/tor/torrc | |
# | |
cat >> /tmp/test << __TOR_CONFIG__ | |
HiddenServiceDir $hsdir | |
HiddenServicePort 22 127.0.0.1:22 | |
__TOR_CONFIG__ | |
# Create the hidden service directory and set perms | |
# | |
mkdir $hsdir | |
chmod 700 $hsdir | |
chown debian-tor:debian-tor $hsdir | |
# Refresh systemd services and start up | |
# | |
systemctl daemon-reload | |
systemctl enable tor | |
systemctl restart tor | |
systemctl status -l tor | |
onionhost="$(cat ${hsdir}/hostname)" | |
# SSH command if using tor DNSPort (nc) | |
# | |
# DNSPort 9053 | |
# AutomapHostsOnResolve 1 | |
# VirtualAddrNetworkIPv4 10.192.0.0/10 | |
echo "Tor DNSPort: ssh -o ProxyCommand=\'nc -x 127.0.0.1:9050 %h %p\' \$(dig +short -p9053 -4 $onionhost @127.0.0.1)" | |
# SSH command if using SOCKSPort (tor-resolve) | |
# | |
echo "Only SOCKSPort: ssh -o ProxyCommand=\'nc -x 127.0.0.1:9050 %h %p\' \$(tor-resolve -4 $onionhost 127.0.0.1:9050)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment