### **πŸš€ How to Configure and Use Tor on Ubuntu for Your Instagram Reel Downloader** This guide will help you **properly configure and run Tor on Ubuntu**, so your script can switch IPs when needed. --- ## **βœ… Step 1: Install Tor** Run the following commands to install Tor and related packages: ```sh sudo apt update && sudo apt install -y tor tor-geoipdb torsocks ``` --- ## **βœ… Step 2: Configure Tor for Your Script** ### **πŸ”Ή Edit the Tor Configuration File** Open the Tor configuration file in a text editor: ```sh sudo nano /etc/tor/torrc ``` ### **πŸ”Ή Enable ControlPort and Set Up Authentication** Find the following lines **(or add them if they don’t exist)**: ``` ControlPort 9051 HashedControlPassword 16:A99A870299D5194560B392D679B27EF6D83E7C324ED30A31C324F7D758 CookieAuthentication 0 ``` πŸ“Œ **Explanation:** - `ControlPort 9051`: Allows your script to communicate with Tor. - `SocksPort 9050` - `HashedControlPassword`: Your **Tor authentication password** (replace it with your own hashed password). - `CookieAuthentication 1`: Disables cookie authentication (not needed for this setup). ### **πŸ”Ή Save the File and Exit** - Press `CTRL + X`, then press `Y` and `ENTER` to save the file. --- ## **βœ… Step 3: Generate a New Hashed Password for Tor (Optional)** If you want to use a **different password**, generate a new hashed password: ```sh tor --hash-password "your_secure_password" ``` This will output something like: ``` 16:4C77919D7AABB6D5E2E3CD5D83297B22A0DB48E2D08F27F0E8CD ``` - **Copy this hash** and **replace it in** `/etc/tor/torrc` under `HashedControlPassword`. --- ## **βœ… Step 4: Restart Tor to Apply Changes** After modifying the `torrc` file, restart the Tor service: ```sh sudo systemctl restart tor sudo systemctl enable tor ``` Check if Tor is running: ```sh sudo systemctl status tor sudo netstat -tulnp | grep 9050 curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip if ip not show tor ``` If everything is fine, you should see: ``` Active: active (running) since ... ``` --- ## **βœ… Step 5: Verify Tor is Working** To check if Tor is working, run: ```sh torsocks curl ifconfig.me ``` - **If the IP is different from your regular IP**, Tor is working! πŸŽ‰ - **If not**, restart the service again: ```sh sudo systemctl restart tor ``` --- ## **βœ… Step 6: Allow Your Script to Change Tor IP** Your script sends a `NEWNYM` signal to Tor to change IPs. **To ensure this works**, try running: ```sh echo -e 'AUTHENTICATE "your_secure_password"\nSIGNAL NEWNYM\nQUIT' | nc localhost 9051 (plain password) ``` - **If no errors appear**, Tor is properly configured. - If **authentication fails**, double-check your `torrc` file and restart Tor. --- ## **πŸš€ Optional: Automate Tor Restart (If Needed)** If your Tor connection frequently fails, **create a cron job to restart Tor every hour**: ```sh sudo crontab -e ``` Add this line: ``` 0 * * * * systemctl restart tor ``` This **restarts Tor every hour** to refresh connections. --- ## **🎯 Summary of Steps** | **Step** | **Command** | |---------|------------| | βœ… Install Tor | `sudo apt install -y tor tor-geoipdb torsocks` | | βœ… Edit Config | `sudo nano /etc/tor/torrc` | | βœ… Add ControlPort | `ControlPort 9051` | | βœ… Add Password | `HashedControlPassword 16:your_generated_hash` | | βœ… Restart Tor | `sudo systemctl restart tor` | | βœ… Check Tor Status | `sudo systemctl status tor` | | βœ… Verify Tor Works | `torsocks curl ifconfig.me` | | βœ… Test IP Change | `echo -e 'AUTHENTICATE "your_password"\nSIGNAL NEWNYM\nQUIT' | nc localhost 9051` | | βœ… Run Python Script | `python3 your_script.py` |