【问题标题】:Connect to google collab with ssh from console from PC从 PC 的控制台使用 ssh 连接到 google collab
【发布时间】:2019-01-23 17:11:15
【问题描述】:

我在网上找到了一个说明如何做到这一点:

#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。任何人都可以给出一些提示吗?我该如何使用它?

【问题讨论】:

  • 你能澄清一下:“它需要一些密钥”吗?
  • 我认为您需要从远程服务器生成密钥并下载它。然后将密钥包含到脚本中。
  • 请粘贴错误转储。

标签: tensorflow ssh ssh-tunnel


【解决方案1】:

我遇到了同样的问题。要解决它,您必须以 root 用户身份 ssh 到实例:

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

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

【讨论】:

    【解决方案2】:

    您需要使用 ngrok 设置一个帐户。

    随后您将收到一个授权码。

    然后您可以进入 ngrok 网站的隧道部分并找到您创建的会话。

    然后ssh进入远程服务器:

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

    并使用代码中生成的密码进行连接。

    【讨论】:

      猜你喜欢
      • 2019-03-11
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-02
      • 2021-03-23
      • 2017-03-01
      相关资源
      最近更新 更多