This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Reverse SSH Tunnel (Stage4) — Полная инструкция
---
# 1️⃣ EDGE — Установить и выполнить Stage4
### 1.1 Сделать скрипт исполняемым
```bash
chmod +x stage4.sh
1.2 Запустить Stage4
sudo bash ./stage4.sh
После выполнения скрипт выведет:
- SSH public key
- Команду для VPS
2️⃣ VPS — Создать / обновить tunnel пользователя
Скопировать и выполнить на VPS команду, которую вывел Stage4:
EDGE_HOSTNAME='g-box-04ba2796'; EDGE_PUBKEY_LINE='ssh-ed25519 AAAA... g-box-04ba2796'; COCKPIT_LOCAL_PORT='9090'; Z2M_LOCAL_PORT='8081'; VPS_USER="tunnel_${EDGE_HOSTNAME}"; sudo useradd -m -s /usr/sbin/nologin "$VPS_USER" 2>/dev/null || true; sudo install -d -m 700 -o "$VPS_USER" -g "$VPS_USER" "/home/$VPS_USER/.ssh"; echo "$EDGE_PUBKEY_LINE" | sudo -u "$VPS_USER" tee "/home/$VPS_USER/.ssh/authorized_keys" >/dev/null; sudo chown "$VPS_USER:$VPS_USER" "/home/$VPS_USER/.ssh/authorized_keys"; sudo chmod 600 "/home/$VPS_USER/.ssh/authorized_keys"; sudo -u "$VPS_USER" sed -i "s@^ssh-ed25519 @command=\"echo Port forwarding only\",no-agent-forwarding,no-X11-forwarding,no-pty,permitopen=\"localhost:9090\",permitopen=\"localhost:8081\" ssh-ed25519 @g" "/home/$VPS_USER/.ssh/authorized_keys"; echo "OK: created/updated $VPS_USER"
3️⃣ EDGE — reverse tunnel запускается автоматом.
В скрипте выполняется строка:
systemctl enable --now iomatex-rt-cockpit.service
Проверить статус
systemctl status iomatex-rt-cockpit
systemctl status iomatex-rt-z2m
systemctl status iomatex-rt-webui
Ожидается:
Active: active (running)
Проверить на VPS:
sudo ss -lntp | grep 22775
4️⃣ Локальная машина (Windows) — Открыть SSH туннель к VPS
Открыть PowerShell и выполнить:
ssh -N -p 22 -L 9090:127.0.0.1:22775 builder@65.109.116.180
(Нужен пароль от VPS для builder)
Окно будет открыто и “висеть” — это нормально.
5️⃣ Открыть Cockpit
Стандартные порты:
https://localhost:9090
Те же процессы для
6️⃣ Открыть Zigbee2MQTT
Стандартные порты:
http://localhost:8081
Если альтернативные:
http://localhost:18081
🔎 Диагностика
Проверка на VPS
ss -lntp | grep -E '19010|18010'
Должно быть:
LISTEN 127.0.0.1:19010
LISTEN 127.0.0.1:18010
4️⃣ Открыть в браузере
Cockpit:
https://localhost:9090
Zigbee2MQTT:
http://localhost:8081
Посмтореть список всех edge на VPS
sudo bash -c 'printf "%-28s %-8s %-8s %-8s %-45s\n" USER COCKPIT Z2M WEBUI KEY; for u in $(getent passwd | awk -F: "/^tunnel_/ {print \$1}"); do ak="/home/$u/.ssh/authorized_keys"; ports=$(grep permitlisten "$ak" 2>/dev/null | sed -n "s/.*127.0.0.1:\([0-9]*\).*127.0.0.1:\([0-9]*\).*127.0.0.1:\([0-9]*\).*/\1 \2 \3/p"); key=$(awk "{print \$3}" "$ak" 2>/dev/null); printf "%-28s %-8s %-8s %-8s %-45s\n" "$u" $ports "$key"; done'
📌 Важно
Используется localhost, а не IP VPS.
Порты пробрасываются через SSH туннель на компьютер.