我想使用scp共享Colab文件,我使用SSH-keygen创建了RSA密钥对。当我运行时:
!scp "/full/path/to/file" [user]@[host]:~/path/to/dest
我得到(没有密码提示):
>>>Host key verification failed.
>>>lost connection
如图所示的经典答案here和here在此上下文中不起作用,因为colab环境不提供访问相关文件的权限:
!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模块:永远的面条,没有任何结果
发布于 2021-08-25 23:27:38
首先,您需要通过一个终端与您的colab帐户建立ssh连接,该终端可以通过ngrok进行连接,代码如下
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
https://stackoverflow.com/questions/56814587
复制相似问题