在 Colab 中打开一个 ssh 并像以前一样执行 tail -f file.log
做。
此选项非常方便,因为您可以调整本地控制台窗口的大小并在 Colab 外部移动它。
感谢一些人,现在真的很容易到达那里。
在单元格上运行它。代码来自here。
# Install colab_ssh
!pip install colab_ssh --upgrade
from colab_ssh import launch_ssh
launch_ssh('YOUR_NGROK_AUTH_TOKEN', 'SOME_PASSWORD')
这将输出类似(截至 2022-02-10)
Collecting colab_ssh
Downloading colab_ssh-0.3.27-py3-none-any.whl (26 kB)
Installing collected packages: colab-ssh
Successfully installed colab-ssh-0.3.27
Warning: Due to some issues with ngrok on Google Colab, reported in the issue https://github.com/WassimBenzarti/colab-ssh/issues/45,
we highly recommend that update your code by following this documentation https://github.com/WassimBenzarti/colab-ssh#getting-started
Successfully running X.tcp.ngrok.io:12345
[Optional] You can also connect with VSCode SSH Remote extension using this configuration:
Host google_colab_ssh
HostName X.tcp.ngrok.io
User root
Port 12345
现在,在您的本地计算机(或任何您想要的地方)上打开控制台并输入。
ssh -p 12345 root@X.tcp.ngrok.io
之后,您就可以进入 Colab 内部了。
tail -f /content/file.log
看着它成长。
在一些不活动之后,连接可能会关闭。
由于主机经常更换,使用 RSA 密钥来避免输入密码似乎不是一个好的解决方案。
所以你可能想安装sshpass
# sudo apt-get install sshpass
因此,您可以在断开连接后简单地重复使用该命令进行连接
# sshpass -p <PASSWORD> ssh -p <PORT> root@X.tcp.ngrok.io