Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Allows you to connect to your Google Colab by using ssh and ngrok.
#@markdown <h2><- Click here to enable SSH.</h2>
#@markdown <h4>Get authtoken from <a href="">ngrok.</a></h4>
import string, time
authtoken = "CHANGE THIS" #@param {type:"string"}
sshpassword = "CHANGE THIS" #@param {type:"string"}
#Download ngrok
! wget -q -c -nc
! unzip -qq -n
#Setup sshd
! apt update > /dev/null
! apt install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null
#Set root password
! echo root:$sshpassword | chpasswd
! mkdir -p /var/run/sshd
#Adds some important ssh configs
! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
! echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
#idk what this is
! echo "LD_LIBRARY_PATH=/usr/lib64-nvidia" >> /root/.bashrc
! echo "export LD_LIBRARY_PATH" >> /root/.bashrc
#Run sshd
get_ipython().system_raw('/usr/sbin/sshd -D &')
#Create tunnel
get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &')
#Print root password
print("Root password: {}".format(sshpassword))
#sleep for five seconds because ngrok takes some time to prep
time.sleep( 5 )
#get url
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"
#@markdown Username is `root`.<br>
#@markdown Connect with the the link given. Be sure to remove `tcp://` when connecting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.