SSH(Google Colab 및 PuTTY)를 통해 가상 머신에 연결

SSH(Google Colab 및 PuTTY)를 통해 가상 머신에 연결

텍스트 편집 기능이 끔찍하고 대화형 셸에 입력하는 문자를 숨기는 것을 좋아하기 때문에 Google Colab 시스템에 SSH로 연결하고 싶습니다.

다음은 Google Colab을 사용하는 Python 3 Jypyter 노트북의 코드입니다.

!echo "PermitRootLogin yes" >> /etc/ssh/sshd_config #gimme that root access, cause default user is root in Google Colab
!cat /etc/ssh/sshd_config                           #check check that everything is A-OK
!mkdir /content/ssh                                 #make an SSH folder
!chmod 700 /content/ssh                             #gimme permissions on that folder
!ssh-keygen -t rsa                                  #make me a key
!curl ifconfig.me                                   #find where i'm at
!restart ssh                                        #restart ssh, IDK why I do this
!service ssh restart

생성되는 출력은 다음과 같습니다.

#   $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem   sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server
PermitRootLogin yes
PasswordAuthentication yes
PermitRootLogin yes
PasswordAuthentication yes
PermitRootLogin yes
PermitRootLogin yes
mkdir: cannot create directory ‘/content/ssh’: File exists
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): key
key already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): SSHNOW
Enter same passphrase again: SSHNOW
Your identification has been saved in key.
Your public key has been saved in key.pub.
The key fingerprint is:
SHA256:k+whmXKgXftXPAr3/zZJlZX85fST0RQOvqJOjBKX5NE root@dc8ab463b697
The key's randomart image is:
+---[RSA 2048]----+
|             ..o=|
|        .   . o+=|
|    . .o E   . +O|
|   o oo=o. .  .+=|
|  . o.*+S ..+.  o|
|     oo+o=.+.. . |
|     . .o+o . . .|
|      . o.   . o.|
|         .    .oo|
+----[SHA256]-----+
35.231.31.81
/bin/bash: restart: command not found

Windows에서 PuTTY를 사용하여 연결하려고 하면[이메일 보호됨]포트 22에서는 네트워크 시간 초과만 수신됩니다.

관련 문제, 제한된 기능: https://stackoverflow.com/questions/48709520/answer-yes-to-terminal-on-google-colaboratory#무슨등산인가 https://stackoverflow.com/questions/51882170/connect-to-google-collab-with-ssh-from-console-from-pc#script는 유용하지만 내가 원하지 않는 추가 작업을 수행합니다. https://research.google.com/colaboratory/local-runtimes.html#로컬 런타임을 사용할 수 없습니다. 매일 5대의 다른 컴퓨터에서 개발합니다.

답변1

포트가 실행 중인 포드에 의해 노출되지 않기 때문에 들어오는 SSH를 사용하여 Colab을 실행하는 머신에 대한 연결을 설정할 수 없습니다(방화벽 뒤에서 실행되고 있음을 읽으십시오).

Colab에서 SSHD를 설정하고 ngrok를 통해 터널링하는 방법에 대한 자세한 설명은 다음과 같습니다.https://stackoverflow.com/a/53252985/888545


더 나은 코드 편집기를 위해 code-server프로젝트를 사용하여 Colab에서 VSCode를 서버로 실행할 수 있습니다(자세한 내용은https://coder.com) 및 ngrok(자세한 내용은https://ngrok.com) 전 세계적으로 액세스 가능한 링크를 얻기 위해.

또한 이 설정을 통해 파일 시스템 브라우저, 코드 편집기, 터미널 및 거의 모든 VSCode 확장에 액세스할 수 있습니다.

코드 서버 및 ngrok 다운로드 및 압축 풀기

!curl -sSL https://github.com/cdr/code-server/releases/download/1.1119-vsc1.33.1/code-server1.1119-vsc1.33.1-linux-x64.tar.gz | tar -xvz
!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
!unzip ngrok-stable-linux-amd64.zip

ngrok 및 코드 서버 실행

!./ngrok http 8443 --log=stdout & ./code-server1.1119-vsc1.33.1-linux-x64/code-server --allow-http --no-auth /

출력에서 다음과 같은 것을 찾으십시오.

msg="started tunnel" obj=tunnels name=command_line addr=http://localhost:8443 url=https://f49b32d9.ngrok.io

그런 다음 링크를 클릭하여 https://xxxx.ngrok.io브라우저의 인코더로 전환하세요.

여기에 이미지 설명을 입력하세요.

관련 정보