# Run Tunnel on Startup for Linux

> Run your Pinggy tunnel on Linux startup with ease. Create a shell script with your Pinggy command and set up a systemd service for automatic execution.
> Source: https://pinggy.io/docs/run_tunnel_on_startup/linux/


# Run Tunnel on Startup for Linux

To run a tunnel on Linux startup, follow these steps:

## Prerequisite

Generate an ssh key, if you don't have one already.
   
   - In your terminal / command prompt run: `ssh-keygen`
   - Press Enter key (Return key) till the command finishes.
   
   This is necessary to skip the password input of the ssh command.

## Step 1: Create a Shell Script

1. **Open a Terminal:**

   - Open your terminal emulator on Linux.

2. **Create a Shell Script:**

   - Use a text editor to create a shell script. For example, you can use `nano`:

     ```bash
     sudo nano /usr/local/sbin/pinggy-startup.sh
     ```

   - Paste your Pinggy command into the script. For example:

     ```bash
     #!/bin/sh
     ssh -p 443 -R0:localhost:8000 -o StrictHostKeyChecking=no -o ServerAliveInterval=30 free.pinggy.io
     ```

   You can customize the command here:

   
```bash
# HTTP tunnel forwarding localhost:8000
ssh -p 443 -R0:localhost:8000 free.pinggy.io
```

   
Configure more options (authentication, web debugger, custom domains, IP whitelisting, header rules) interactively at https://pinggy.io/docs/run_tunnel_on_startup/linux/


   - Save and exit the text editor.

3. **Make the Script Executable:**
   - Run the following command to make your script executable:
     ```bash
     sudo chmod +x /usr/local/sbin/pinggy-startup.sh
     ```

## Step 2: Create a Systemd Service

1. **Create a Systemd Service File:**

   - Use a text editor to create a systemd service file. For example:

     ```bash
     sudo nano /etc/systemd/system/pinggy-startup.service
     ```

   - Paste the following content into the file:

     ```ini
     [Unit]
     Description=Pinggy Tunnel Startup
     After=network.target

     [Service]
     ExecStart=/usr/local/sbin/pinggy-startup.sh
     Restart=on-failure
     RestartSec=10s

     [Install]
     WantedBy=multi-user.target
     ```

   - Save and exit the text editor.

2. **Reload Systemd and Enable the Service:**
   - Run the following commands to reload systemd and enable your service:
     ```bash
     sudo systemctl daemon-reload
     sudo systemctl enable pinggy-startup.service
     sudo systemctl start pinggy-startup.service
     ```

## Step 3: Verify and Monitor the Service

1. **Check Service Status:**

   - Run the following command to check the status of your service:

     ```bash
     sudo systemctl status pinggy-startup.service
     ```

   ![Linux System Service Status](/doc_img/linux_system_service_status.webp)


2. **View Service Logs:**

   - Use the following command to view the logs of your service:
     ```bash
     sudo journalctl -u pinggy-startup.service
     ```

   ![Linux Logs](/doc_img/linux_logs.webp)


Now, your Pinggy tunnel will automatically execute each time your Linux system starts up.

