星期二, 6月 17, 2025

防止 putty ssh timeout

我用 vast.ai 訓練 AI 對 ssh tunnel 有很大的依賴。一個困擾許久的問題是 TCP timeout,只要 ssh 一斷 tunnel 就跟著斷,然後透過 tunnel 跑的 notebook 就跟著死了。

用過 putty 內建的 TCP keepalive 完全沒用,後來寫 bash 腳本不停輸出資料,問題好像就改善了,紀錄一下 :P

#!/bin/bash

# Prevent TCP timeout by sending output every second
while true; do
    echo "Still alive: $(date)"
    sleep 1
done
全文連結