首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Colab将文件发送到主机

使用Colab将文件发送到主机
EN

Stack Overflow用户
提问于 2019-06-29 09:59:27
回答 1查看 642关注 0票数 6

我想使用scp共享Colab文件,我使用SSH-keygen创建了RSA密钥对。当我运行时:

代码语言:javascript
运行
复制
!scp "/full/path/to/file"  [user]@[host]:~/path/to/dest

我得到(没有密码提示):

代码语言:javascript
运行
复制
>>>Host key verification failed.
>>>lost connection

如图所示的经典答案herehere在此上下文中不起作用,因为colab环境不提供访问相关文件的权限:

代码语言:javascript
运行
复制
!ssh-keygen -R [host]
>>>do_known_hosts: hostkeys_foreach failed: No such file or directory

!rm /home/USERNAME/.ssh/known_hosts
>>>rm: cannot remove '/home/USERNAME/.ssh/known_hosts': No such file or directory

!scp "/full/path/to/file" -o 'StrictHostKeyChecking no' [user]@[host]:~/path/to/dest

相同的

paramiko pip模块:永远的面条,没有任何结果

EN

回答 1

Stack Overflow用户

发布于 2021-08-25 23:27:38

首先,您需要通过一个终端与您的colab帐户建立ssh连接,该终端可以通过ngrok进行连接,代码如下

代码语言:javascript
运行
复制
import random, string, urllib.request, json, getpass

#Generate root password
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")
authtoken = getpass.getpass()

#Create tunnel
get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &')

#Get public address and print connect command
with urllib.request.urlopen('http://localhost:4040/api/tunnels') as response:
  data = json.loads(response.read().decode())
  (host, port) = data['tunnels'][0]['public_url'][6:].split(':')
  print(f'SSH command: ssh -p{port} root@{host}')

#Print root password
print(f'Root password: {password}')

通过终端连接到colab后,您可以在该终端上使用SCP

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56814587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档