PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Generate a vanity hostname for v3 onion link for tor on linux

Go down

Generate a vanity hostname for v3 onion link for tor on linux Empty Generate a vanity hostname for v3 onion link for tor on linux

Post by jamied_uk 10th November 2024, 23:00

Code:
#!/bin/bash
# (c) J~Net 2024
#
# Usage: sudo ./generate.sh

DEFAULT_PREFIX="jnet"

# Prompt user for the desired prefix, defaulting to "jnet" if none provided
read -p "Enter Desired Short Prefix (max 6 chars, default is '$DEFAULT_PREFIX'): " PREFIX

# Use default if no prefix is entered
if [ -z "$PREFIX" ]; then
    PREFIX="$DEFAULT_PREFIX"
    echo "No Prefix Entered. Using Default Prefix: '$PREFIX'"
fi

# Ensure prefix does not exceed 6 characters
if [ "${#PREFIX}" -gt 6 ]; then
    echo "Error: Prefix too long. Use a prefix of up to 6 characters."
    exit 1
fi

while true; do
    # Stop Tor to safely regenerate hidden service keys
    sudo systemctl stop tor
    sleep 5  # Allow time for Tor to fully stop

    # Remove the hidden service directory completely to avoid caching issues
    sudo rm -rf /var/lib/tor/hidden_service
    sleep 2  # Small delay to ensure the directory is fully removed

    # Recreate the hidden service directory with proper permissions
    sudo mkdir -p /var/lib/tor/hidden_service
    sudo chown -R debian-tor:debian-tor /var/lib/tor/hidden_service
    sudo chmod 700 /var/lib/tor/hidden_service

    # Start Tor to regenerate the hidden service keys
    sudo systemctl start tor
    sleep 20  # Wait for Tor to generate the keys

    # Retrieve and display the generated hostname
    HOSTNAME=$(sudo cat /var/lib/tor/hidden_service/hostname 2>/dev/null)
    if [ -z "$HOSTNAME" ]; then
        echo "Hostname not generated yet. Retrying..."
        sleep 5
        continue
    fi

    echo "Generated Address: $HOSTNAME"
    
    # Check if the hostname begins with the desired prefix
    if [[ "$HOSTNAME" == "$PREFIX"* ]]; then
        echo "Successfully Generated a V3 Onion Address Starting with '$PREFIX': $HOSTNAME"
        
        # Set permissions for security
        sudo chown -R debian-tor:debian-tor /var/lib/tor/hidden_service
        sudo chmod 700 /var/lib/tor/hidden_service
        sudo chmod 600 /var/lib/tor/hidden_service/*
        
        echo "Permissions set to secure defaults."
        break
    else
        echo "Generated Address Does Not Start With '$PREFIX'. Retrying..."
    fi
done
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum