【免费VM/VPS虚拟服务器】一键运行创建终身免费的VM/VPS服务器,支持SSH和RDP连接Ubuntu、macOS、windows三大系统

【免费VM/VPS虚拟服务器】一键运行创建终身免费的VM/VPS服务器,支持SSH和RDP连接Ubuntu、macOS、windows三大系统
[点击观看视频教程]

【YouTube频道】 | 【Telegram频道】 | 【GitHub仓库】

支持Ubuntu、macOS、windows三个系统的免费VM/VPS虚拟服务器,供2种可选的SSH连接方式tmate和ngrok连接Ubuntu、macOS,一种RDP连接windows
来自网络和P3TERX(https://github.com/P3TERX/ssh2actions)修改更新实现最新版本连接
大家可以用来学习不同系统的相关知识,请勿滥用

《部署教程说明》

一、需要准备的前提资料

1、首先注册ngrok账号,使用ngrok来穿透内网

2、获取SSH连接工具,请加下群AM科技|分享交流群发送关键字: ssh

二、通过tmate安装GitHub Actions VM (SSH免费连接VM服务器Ubuntu、macOS)

  • 1、tmate2actions.sh

    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    #!/usr/bin/env bash

    set -e
    Green_font_prefix="\033[32m"
    Red_font_prefix="\033[31m"
    Green_background_prefix="\033[42;37m"
    Red_background_prefix="\033[41;37m"
    Font_color_suffix="\033[0m"
    INFO="[${Green_font_prefix}INFO${Font_color_suffix}]"
    ERROR="[${Red_font_prefix}ERROR${Font_color_suffix}]"
    TMATE_SOCK="/tmp/tmate.sock"
    TELEGRAM_LOG="/tmp/telegram.log"
    CONTINUE_FILE="/tmp/continue"

    # Install tmate on macOS or Ubuntu
    echo -e "${INFO} Setting up tmate ..."
    if [[ -n "$(uname | grep Linux)" ]]; then
    curl -fsSL git.io/tmate.sh | bash
    elif [[ -x "$(command -v brew)" ]]; then
    brew install tmate
    else
    echo -e "${ERROR} This system is not supported!"
    exit 1
    fi

    # Generate ssh key if needed
    [[ -e ~/.ssh/id_rsa ]] || ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -N ""

    # Run deamonized tmate
    echo -e "${INFO} Running tmate..."
    tmate -S ${TMATE_SOCK} new-session -d
    tmate -S ${TMATE_SOCK} wait tmate-ready

    # Print connection info
    TMATE_SSH=$(tmate -S ${TMATE_SOCK} display -p '#{tmate_ssh}')
    TMATE_WEB=$(tmate -S ${TMATE_SOCK} display -p '#{tmate_web}')
    MSG="
    *GitHub Actions - tmate session info:*

    ⚡ *CLI:*
    \`${TMATE_SSH}\`

    🔗 *URL:*
    ${TMATE_WEB}

    🔔 *TIPS:*
    Run '\`touch ${CONTINUE_FILE}\`' to continue to the next step.
    "

    if [[ -n "${TELEGRAM_BOT_TOKEN}" && -n "${TELEGRAM_CHAT_ID}" ]]; then
    echo -e "${INFO} Sending message to Telegram..."
    curl -sSX POST "${TELEGRAM_API_URL:-https://api.telegram.org}/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
    -d "disable_web_page_preview=true" \
    -d "parse_mode=Markdown" \
    -d "chat_id=${TELEGRAM_CHAT_ID}" \
    -d "text=${MSG}" >${TELEGRAM_LOG}
    TELEGRAM_STATUS=$(cat ${TELEGRAM_LOG} | jq -r .ok)
    if [[ ${TELEGRAM_STATUS} != true ]]; then
    echo -e "${ERROR} Telegram message sending failed: $(cat ${TELEGRAM_LOG})"
    else
    echo -e "${INFO} Telegram message sent successfully!"
    fi
    fi

    while ((${PRT_COUNT:=1} <= ${PRT_TOTAL:=10})); do
    SECONDS_LEFT=${PRT_INTERVAL_SEC:=10}
    while ((${PRT_COUNT} > 1)) && ((${SECONDS_LEFT} > 0)); do
    echo -e "${INFO} (${PRT_COUNT}/${PRT_TOTAL}) Please wait ${SECONDS_LEFT}s ..."
    sleep 1
    SECONDS_LEFT=$((${SECONDS_LEFT} - 1))
    done
    echo "-----------------------------------------------------------------------------------"
    echo "To connect to this session copy and paste the following into a terminal or browser:"
    echo -e "CLI: ${Green_font_prefix}${TMATE_SSH}${Font_color_suffix}"
    echo -e "URL: ${Green_font_prefix}${TMATE_WEB}${Font_color_suffix}"
    echo -e "TIPS: Run 'touch ${CONTINUE_FILE}' to continue to the next step."
    echo "-----------------------------------------------------------------------------------"
    PRT_COUNT=$((${PRT_COUNT} + 1))
    done

    while [[ -S ${TMATE_SOCK} ]]; do
    sleep 1
    if [[ -e ${CONTINUE_FILE} ]]; then
    echo -e "${INFO} Continue to the next step."
    exit 0
    fi
    done

  • 2、tmate-ubuntu.yml文件

    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
    name: 'tmate-ubuntu'

    on:
    workflow_dispatch:
    inputs:
    mode:
    description: 'Choose tmate or ngrok mode'
    required: false
    default: 'tmate'

    jobs:
    ssh-debug:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
    uses: actions/checkout@v2 # 检出你的代码仓库

    - name: Choose mode tmate (ubuntu)
    run: |
    MODE=${{ github.event.inputs.mode }}
    bash ./${MODE}2actions.sh # 使用相对路径执行脚本
    shell: bash

    - name: Sleep
    run: sleep 6h
  • 3、tmate-macos.yml文件

    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
    name: 'tmate-macos'

    on:
    workflow_dispatch:
    inputs:
    mode:
    description: 'Choose tmate or ngrok mode'
    required: false
    default: 'tmate'

    jobs:
    ssh-debug:
    runs-on: macos-latest
    steps:
    - name: Checkout repository
    uses: actions/checkout@v2 # 检出你的代码仓库

    - name: Choose mode tmate (macos)
    run: |
    MODE=${{ github.event.inputs.mode }}
    bash ./${MODE}2actions.sh # 使用相对路径执行脚本
    shell: bash

    - name: Sleep
    run: sleep 6h

三、通过ngrok安装GitHub Actions VM (SSH免费连接VM服务器Ubuntu、macOS)

前提配置github变量 NGROK_TOKEN

在当前项目找到 Settings -> Secrets and variables -> Actions -> Repository secrets -> 然后点New repository secret创建变量 填下ngrok的Authtoken值

1
2
- 注册成功后查看Authtoken地址,复制token下来就可以
https://dashboard.ngrok.com/get-started/your-authtoken

前提配置github变量 SSH_PASSWORD

在当前项目找到 Settings -> Secrets and variables -> Actions -> Repository secrets -> 然后点New repository secret创建变量 填到时要登录服务器的密码

  • 1、ngrok2actions.sh

    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    #!/usr/bin/env bash

    Green_font_prefix="\033[32m"
    Red_font_prefix="\033[31m"
    Green_background_prefix="\033[42;37m"
    Red_background_prefix="\033[41;37m"
    Font_color_suffix="\033[0m"
    INFO="[${Green_font_prefix}INFO${Font_color_suffix}]"
    ERROR="[${Red_font_prefix}ERROR${Font_color_suffix}]"
    LOG_FILE='/tmp/ngrok.log'
    TELEGRAM_LOG="/tmp/telegram.log"
    CONTINUE_FILE="/tmp/continue"

    if [[ -z "${NGROK_TOKEN}" ]]; then
    echo -e "${ERROR} Please set 'NGROK_TOKEN' environment variable."
    exit 2
    fi

    if [[ -z "${SSH_PASSWORD}" && -z "${SSH_PUBKEY}" && -z "${GH_SSH_PUBKEY}" ]]; then
    echo -e "${ERROR} Please set 'SSH_PASSWORD' environment variable."
    exit 3
    fi

    if [[ -n "$(uname | grep -i Linux)" ]]; then
    echo -e "${INFO} Install ngrok ..."
    curl -fsSL https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.zip -o ngrok.zip
    unzip ngrok.zip ngrok
    rm ngrok.zip
    chmod +x ngrok
    sudo mv ngrok /usr/local/bin
    ngrok -v
    elif [[ -n "$(uname | grep -i Darwin)" ]]; then
    echo -e "${INFO} Install ngrok ..."
    curl -fsSL https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-darwin-amd64.zip -o ngrok.zip
    unzip ngrok.zip ngrok
    rm ngrok.zip
    chmod +x ngrok
    sudo mv ngrok /usr/local/bin
    ngrok -v
    USER=root
    echo -e "${INFO} Set SSH service ..."
    echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config >/dev/null
    sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
    sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
    else
    echo -e "${ERROR} This system is not supported!"
    exit 1
    fi

    if [[ -n "${SSH_PASSWORD}" ]]; then
    echo -e "${INFO} Set user(${USER}) password ..."
    echo -e "${SSH_PASSWORD}\n${SSH_PASSWORD}" | sudo passwd "${USER}"
    fi

    echo -e "${INFO} Start ngrok proxy for SSH port..."
    screen -dmS ngrok \
    ngrok tcp 22 \
    --log "${LOG_FILE}" \
    --authtoken "${NGROK_TOKEN}" \
    --region "${NGROK_REGION:-us}"

    while ((${SECONDS_LEFT:=10} > 0)); do
    echo -e "${INFO} Please wait ${SECONDS_LEFT}s ..."
    sleep 1
    SECONDS_LEFT=$((${SECONDS_LEFT} - 1))
    done

    ERRORS_LOG=$(grep "command failed" ${LOG_FILE})

    if [[ -e "${LOG_FILE}" && -z "${ERRORS_LOG}" ]]; then
    SSH_CMD="$(grep -oE "tcp://(.+)" ${LOG_FILE} | sed "s/tcp:\/\//ssh ${USER}@/" | sed "s/:/ -p /")"
    MSG="
    *GitHub Actions - ngrok session info:*

    ⚡ *CLI:*
    \`${SSH_CMD}\`

    🔔 *TIPS:*
    Run '\`touch ${CONTINUE_FILE}\`' to continue to the next step.
    "
    if [[ -n "${TELEGRAM_BOT_TOKEN}" && -n "${TELEGRAM_CHAT_ID}" ]]; then
    echo -e "${INFO} Sending message to Telegram..."
    curl -sSX POST "${TELEGRAM_API_URL:-https://api.telegram.org}/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
    -d "disable_web_page_preview=true" \
    -d "parse_mode=Markdown" \
    -d "chat_id=${TELEGRAM_CHAT_ID}" \
    -d "text=${MSG}" >${TELEGRAM_LOG}
    TELEGRAM_STATUS=$(cat ${TELEGRAM_LOG} | jq -r .ok)
    if [[ ${TELEGRAM_STATUS} != true ]]; then
    echo -e "${ERROR} Telegram message sending failed: $(cat ${TELEGRAM_LOG})"
    else
    echo -e "${INFO} Telegram message sent successfully!"
    fi
    fi
    while ((${PRT_COUNT:=1} <= ${PRT_TOTAL:=10})); do
    SECONDS_LEFT=${PRT_INTERVAL_SEC:=10}
    while ((${PRT_COUNT} > 1)) && ((${SECONDS_LEFT} > 0)); do
    echo -e "${INFO} (${PRT_COUNT}/${PRT_TOTAL}) Please wait ${SECONDS_LEFT}s ..."
    sleep 1
    SECONDS_LEFT=$((${SECONDS_LEFT} - 1))
    done
    echo "------------------------------------------------------------------------"
    echo "To connect to this session copy and paste the following into a terminal:"
    echo -e "${Green_font_prefix}$SSH_CMD${Font_color_suffix}"
    echo -e "TIPS: Run 'touch ${CONTINUE_FILE}' to continue to the next step."
    echo "------------------------------------------------------------------------"
    PRT_COUNT=$((${PRT_COUNT} + 1))
    done
    else
    echo "${ERRORS_LOG}"
    exit 4
    fi

    while [[ -n $(ps aux | grep ngrok) ]]; do
    sleep 1
    if [[ -e ${CONTINUE_FILE} ]]; then
    echo -e "${INFO} Continue to the next step."
    exit 0
    fi
    done


  • 2、ngrok-ubuntu.yml文件

    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
    name: 'ngrok-ubuntu'

    on:
    workflow_dispatch:
    inputs:
    mode:
    description: 'Choose tmate or ngrok mode'
    required: false
    default: 'ngrok'

    jobs:
    ssh-debug:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
    uses: actions/checkout@v2 # 检出你的代码仓库

    - name: Choose mode ngrok (ubuntu)
    env:
    NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }}
    SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
    run: |
    MODE=${{ github.event.inputs.mode }}
    bash ./${MODE}2actions.sh # 使用相对路径执行脚本
    shell: bash

    - name: Sleep
    run: sleep 6h
  • 3、ngrok-macos.yml文件

    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
    name: 'ngrok-macos'

    on:
    workflow_dispatch:
    inputs:
    mode:
    description: 'Choose tmate or ngrok mode'
    required: false
    default: 'ngrok'

    jobs:
    ssh-debug:
    runs-on: macos-latest
    steps:
    - name: Checkout repository
    uses: actions/checkout@v2 # 检出你的代码仓库

    - name: Choose mode ngrok (macos)
    env:
    NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }}
    SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
    run: |
    MODE=${{ github.event.inputs.mode }}
    bash ./${MODE}2actions.sh # 使用相对路径执行脚本
    shell: bash

    - name: Sleep
    run: sleep 6h

  • 相同系统的两个yml文件可以部署一个就可以,因为运行时可以输入参数选择tmate还是ngrok运行的

四、通过ngrok安装GitHub Actions VM (RDP免费连接VM服务器windows)

前提配置github变量 NGROK_TOKEN

在当前项目找到 Settings -> Secrets and variables -> Actions -> Repository secrets -> 然后点New repository secret创建变量 填下ngrok的Authtoken值

1
2
- 注册成功后查看Authtoken地址,复制token下来就可以
https://dashboard.ngrok.com/get-started/your-authtoken

前提配置github变量 SSH_PASSWORD

在当前项目找到 Settings -> Secrets and variables -> Actions -> Repository secrets -> 然后点New repository secret创建变量 填到时要登录服务器的密码

  • 1、ngrok-windows.yml文件
    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
    name: ngrok-windows

    on:
    workflow_dispatch:

    jobs:
    build:
    runs-on: windows-latest
    steps:
    - name: Download ngrok
    run: Invoke-WebRequest https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-windows-amd64.zip -OutFile ngrok.zip
    - name: Extract ngrok
    run: Expand-Archive ngrok.zip
    - name: Authenticate with ngrok
    run: .\ngrok\ngrok.exe authtoken $Env:NGROK_TOKEN
    env:
    NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }}
    - name: Enable Remote Desktop
    run: |
    Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
    Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
    Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1
    Set-LocalUser -Name "runneradmin" -Password (ConvertTo-SecureString -AsPlainText $Env:SSH_PASSWORD -Force)
    env:
    SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
    - name: Create ngrok tunnel to remote desktop
    run: .\ngrok\ngrok.exe tcp 3389

➖➖➖➖➖➖➖➖➖➖➖➖➖
▶️ 新人YouTube 需要您的支持,请务必帮我点赞关注打开小铃铛十分感谢!!!

🎁 不要只是下载或Fork。请 follow 我的GitHub、给我所有项目一个 Star 星星(拜托了)!你的支持是我不断前进的动力! 💖

[点击展开] 赞赏支持 ~🧧 *我非常感谢您的赞赏和支持,它们将极大地激励我继续创新,持续产生有价值的工作。*
  • USDT-TRC20: TWTxUyay6QJN3K4fs4kvJTT8Zfa2mWTwDD

➖➖➖➖➖广告位➖➖➖➖
【红杏加速器】机场,专属全场套餐5折,低至5元左右222G,数量有限,先到先得!!!
点击官网【注册地址】注册
5折优惠码:AM科技
多条高速iepl专线,独家定制极速机场专线,玩游戏首选,支持奈飞,chatGPT,tiktok等8K流媒体。

➖➖➖➖➖➖➖➖➖➖➖➖➖
【69云】中转高速机场
点击官网【https://am.69yun69.com】注册
✅看片秒加载,全流媒体解锁,Chatgpt解锁web+app!
🎁不限时套餐,永久有效,让您的流量永不过期。签到,每日免费流量
✅双千兆节点,一秒下载不卡顿!低至9.9元400G

➖➖➖➖➖➖➖➖➖➖➖➖➖
【云狐VPN】专线机场
点击官网【https://yunfox.cc】注册
✔️无视晚高峰,高清流畅体验Netflix、Disney+等,可配置中转静态住宅IP,Chat GPT专线,海外社交流媒体全解锁。

➖➖➖➖➖➖➖➖➖➖➖➖➖