Shell Loop
for me, I choose ,chroot into VM by ssh Ngrok and run command shell (loop) in background
while true;do sleep 300; done &
I'm using&` for to run this command in the background
so I can exit from website of colab and leave the VM working, for 12h
ssh Ngrok
The best way to use ssh in colab , you must sign one time in ngrok.com
and get your OAuth key and add this cell to your colab notebook
#@title **SSH**
! pip install colab_ssh --upgrade &> /dev/null
Ngrok = True
try:
if username:
pass
elif password:
pass
except NameError:
!echo "root:root" | chpasswd
username='root'
password='root'
#@markdown [OAuth](https://dashboard.ngrok.com/auth)
ngrokToken = "" #@param {type:'string'}
def runNGROK():
from colab_ssh import launch_ssh
from IPython.display import clear_output
launch_ssh(ngrokToken, password)
clear_output()
print("ssh", username, end='@')
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'][6:].replace(':', ' -p '))"
if Ngrok:
if ngrokToken == "":
print("No ngrokToken Found, Please enter it")
else:
runNGROK()
now past your OAuth key in Edite text in colab cell , after 3-9 seconde you see your ssh like that
ssh root@2.tcp.ngrok.io -p 13225
dont forget change password of root user (default is root) ,for more security, you should be change linux password of root user !echo "root:new password" | chpasswd
and from python variable by : password =password='new password'
, you must matching linux password and var python password , look in this ligne above:
print("No user found using username and password as 'root'")
!echo "root:t" | chpasswd
username='root'
password='root'