forked from murad0x69/run
-
Notifications
You must be signed in to change notification settings - Fork 0
42 lines (34 loc) · 1.54 KB
/
Copy pathssh.yml
File metadata and controls
42 lines (34 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: SSH Access to Runner
on: workflow_dispatch
jobs:
ssh-access:
runs-on: ubuntu-latest
steps:
- name: Setup Tmate Session
run: |
# Install tmate
sudo apt-get update
sudo apt-get install -y tmate openssh-client
# Generate SSH key
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
# Start tmate
tmate -S /tmp/tmate.sock new-session -d
tmate -S /tmp/tmate.sock wait tmate-ready
# Get connection strings
SSH_CMD=$(tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}')
WEB_URL=$(tmate -S /tmp/tmate.sock display -p '#{tmate_web}')
# Escape special characters for MarkdownV2
ESCAPED_SSH_CMD=$(echo "$SSH_CMD" | sed -e 's/\./\\./g' -e 's/\-/\\-/g' -e 's/_/\\_/g' -e 's/`/\\`/g')
ESCAPED_WEB_URL=$(echo "$WEB_URL" | sed -e 's/\./\\./g' -e 's/\-/\\-/g' -e 's/_/\\_/g')
# Format for Telegram
MSG="🔐 SSH Access Details%0A%0A"
MSG+="SSH Command: \`$ESCAPED_SSH_CMD\`%0A" # Properly escaped backticks
MSG+="Web URL: $ESCAPED_WEB_URL%0A%0A"
MSG+="Note: Session will remain active for 1 hour"
# Send via Telegram
curl -s "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
-d "text=$MSG" \
-d "parse_mode=MarkdownV2"
- name: Keep Alive
run: sleep 1h # Keeps the runner alive for 1 hour