从 PC 的控制台使用 ssh 连接到 google collab [英] Connect to google collab with ssh from console from PC

查看:19
本文介绍了从 PC 的控制台使用 ssh 连接到 google collab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到了一条如何操作的说明:

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'])"

它需要一些密钥,但我不明白从哪里获得这个密钥以及如何使用这种方法从我的 PC 连接到 ssh.任何人都可以提供一些提示吗?我该如何使用它?

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?

推荐答案

我遇到了同样的问题.要解决它,您必须以 root 用户身份通过​​ ssh 连接到实例:

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

ssh root@0.tcp.ngrok.io -p <your_port>

然后当它提示您输入密码时,您必须粘贴在脚本开头随机生成的密码(在脚本的 password 变量中找到)

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)

这篇关于从 PC 的控制台使用 ssh 连接到 google collab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆