Skip to content

Instantly share code, notes, and snippets.

@qingy1337
Last active June 13, 2025 15:30
Show Gist options
  • Save qingy1337/03e2f09a9cf6c102958a9cdceb51e2f0 to your computer and use it in GitHub Desktop.
Save qingy1337/03e2f09a9cf6c102958a9cdceb51e2f0 to your computer and use it in GitHub Desktop.

Revisions

  1. qingy1337 revised this gist Jun 13, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tailscale.md
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,8 @@ Requires=tailscaled.service
    Wants=network-online.target
    [Service]
    ExecStart=/usr/bin/tailscale up --authkey-file=/etc/tailscale/authkey --accept-routes=true --accept-dns=true
    Restart=on-failure
    ExecStart=/usr/bin/tailscale up ––auth–key file:/etc/tailscale/authkey ––acceptroutes
    Restart=onfailure
    RestartSec=5s
    StartLimitInterval=60s
    StartLimitBurst=3
  2. qingy1337 revised this gist Jun 13, 2025. 1 changed file with 32 additions and 3 deletions.
    35 changes: 32 additions & 3 deletions tailscale.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,12 @@
    To set up the auth key, run:

    ```

    To automatically authenticate Tailscale on startup in Ubuntu, follow these steps:

    1. Generate a reusable auth key from the Tailscale admin console at https://login.tailscale.com/admin/authkeys. Make sure to select the appropriate options for your use case (e.g., whether the node is ephemeral or not).

    2. On your Ubuntu machine, run the following commands to set up the auth key and create a systemd service:

    ```bash
    # Create a directory for the auth key
    sudo mkdir -p /etc/tailscale

    @@ -32,4 +38,27 @@ EOF
    sudo systemctl daemon-reload
    sudo systemctl enable tailscale-up.service
    sudo systemctl start tailscale-up.service
    ```
    ```

    3. Verify that the service is running correctly:

    ```bash
    sudo systemctl status tailscale-up.service
    tailscale status
    ```

    4. If you need to update the auth key in the future, simply update the `/etc/tailscale/authkey` file with the new key and restart the service:

    ```bash
    sudo systemctl restart tailscale-up.service
    ```

    This setup will ensure that your machine automatically authenticates and connects to the Tailscale network on boot. Make sure to adjust the flags in the `tailscale up` command (e.g., `--accept-routes`, `--accept-dns`) based on your specific requirements.

    If you encounter any issues, you can check the logs for the service with:

    ```bash
    sudo journalctl -u tailscale-up.service
    ```

    This should help you diagnose any problems with the authentication process.
  3. qingy1337 created this gist Jun 13, 2025.
    35 changes: 35 additions & 0 deletions tailscale.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    To set up the auth key, run:

    ```
    # Create a directory for the auth key
    sudo mkdir -p /etc/tailscale
    # Store the auth key in a file with secure permissions
    # Replace 'tskey-auth-abc123' with the actual auth key you generated.
    echo "tskey-auth-abc123" | sudo tee /etc/tailscale/authkey
    sudo chmod 600 /etc/tailscale/authkey
    # Create the systemd service file
    sudo tee /etc/systemd/system/tailscale-up.service <<EOF
    [Unit]
    Description=Tailscale Up
    After=tailscaled.service network-online.target
    Requires=tailscaled.service
    Wants=network-online.target
    [Service]
    ExecStart=/usr/bin/tailscale up --authkey-file=/etc/tailscale/authkey --accept-routes=true --accept-dns=true
    Restart=on-failure
    RestartSec=5s
    StartLimitInterval=60s
    StartLimitBurst=3
    [Install]
    WantedBy=multi-user.target
    EOF
    # Enable and start the new service
    sudo systemctl daemon-reload
    sudo systemctl enable tailscale-up.service
    sudo systemctl start tailscale-up.service
    ```