Stepan Yakovenko
Stepan Yakovenko

Reputation: 9226

Connect to google collab with ssh from console from PC

I've found one instruction on the net how to do it:

#Generate root password
import random, string
password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20))

#Download ngrok
! wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
! unzip -qq -n ngrok-stable-linux-amd64.zip
#Setup sshd
! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null
#Set root password
! echo root:$password | chpasswd
! mkdir -p /var/run/sshd
! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
! echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
! 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 &')

#Ask token
print("Copy authtoken from https://dashboard.ngrok.com/auth")
import getpass
authtoken = getpass.getpass()

#Create tunnel
get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &')
#Print root password
print("Root password: {}".format(password))
#Get public address
! curl -s http://localhost:4040/api/tunnels | python3 -c \
    "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"

it asks for some key, but I don't understand where to get this key and how to use this approach to connect from my PC with ssh. Can any one give some hint? How can I use this?

Upvotes: 4

Views: 5835

Answers (2)

DeWil
DeWil

Reputation: 362

You need to setup an account with ngrok.

Followed by which you will receive an authorisation code.

You can then got to the tunnels section of ngrok website and find the session you created.

Then ssh into the remote server:

ssh [email protected] -p <port_number>

and use the password generated in the code to connect.

Upvotes: 0

hellter
hellter

Reputation: 1004

I had your same issue. To solve it you have to ssh to the instance as root user:

ssh [email protected] -p <your_port>

And then when it prompts you for a password you have to paste the password that's randomly generated at the beginning of the script (found in the password variable in your script)

Upvotes: 6

Related Questions