/ Setting Up a Tor Onion Service
A complete guide to creating a Tor beacon. Since Tor addresses are persistent, this is a perfect way to access devices or servers that are inside a network you can not control.
NOTE: Onion services provide additional privacy and censorship resistance. They allow visitors to access your service anonymously through the Tor network.
// What is a Tor Onion Service?
An onion service (formerly called a "hidden service") allows you to host a website or provide SSH access (as in our example), accessible only through the Tor network. Visitors gain enhanced privacy, and your service becomes more resistant to censorship and surveillance.
// Prerequisites
- Linux server with root access
// Automated Setup Script
Save this script as tor-setup.sh and run as root:
#!/bin/bash
# Tor Onion Service Setup Script
# Run as root: sudo ./tor-setup.sh
echo "Setting up Tor onion service..."
# Install Tor if not already installed
if ! command -v tor &> /dev/null; then
echo "Installing Tor..."
apt update
apt install -y tor
fi
# Create onion service directory
mkdir -p /var/lib/tor/website_onion/
chown debian-tor:debian-tor /var/lib/tor/website_onion/
chmod 700 /var/lib/tor/website_onion/
# Backup original torrc
cp /etc/tor/torrc /etc/tor/torrc.backup.$(date +%Y%m%d)
# Add onion service configuration to torrc
cat >> /etc/tor/torrc << 'EOF'
# Onion service for website
HiddenServiceDir /var/lib/tor/website_onion/
HiddenServicePort 80 127.0.0.1:80
HiddenServiceVersion 3
EOF
# Restart tor service
systemctl restart tor
systemctl enable --now tor
echo "Waiting for Tor to generate onion address..."
sleep 5
# Display the onion address
if [ -f /var/lib/tor/website_onion/hostname ]; then
ONION_ADDRESS=$(cat /var/lib/tor/website_onion/hostname)
echo "==============================================="
echo "Onion service configured successfully!"
echo "Your onion address is: $ONION_ADDRESS"
echo "==============================================="
echo "Add this to your website footer:"
echo "<a href="http://$ONION_ADDRESS">🧅 Onion Mirror</a>"
echo "==============================================="
else
echo "Error: Could not generate onion address. Check /var/log/tor/log"
fi
Once this is running you can access the server from anywhere on the world through tor.
$ torify ssh <user>@<youronionaddress>