colab-sshを用いたssh接続
以前までは、ngrokサービスを用いてgoogle colabにログインしていたのですが、下記の問題が解決できず、代替案として、colab-sshを用いてgoogle colabにアクセスしてみた。
https://github.com/WassimBenzarti/colab-ssh
接続方法
1. Google Colab notebookを実行します。
2. notebookのcellに下記コードを入力します。
# Install colab_ssh on google colab !pip install colab_ssh --upgrade from colab_ssh import launch_ssh_cloudflared, init_git_cloudflared password="hogehoge" # hogehogeという名前でパスワードを追加しました。 launch_ssh_cloudflared(password)
3. クライアントPC側で下記の設定をします。
4. Cloudflared (Argo Tunnel)をインストールします。
私の場合、mac OS Big SURでしたので下記コマンドを実行しました。
brew install cloudflare/cloudflare/cloudflared
また私の場合、xcode-selectが古いためか、上記コマンド実行時に下記のエラーが発生しました。
brew install cloudflare/cloudflare/cloudflared fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Updating Homebrew... fatal: 'origin/master' is not a commit and a branch 'master' cannot be created from it fatal: invalid upstream 'origin/master' ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core and caskroom/cask). ==> Updated Casks one-switch ==> Tapping cloudflare/cloudflare Cloning into '/usr/local/Homebrew/Library/Taps/cloudflare/homebrew-cloudflare'... remote: Enumerating objects: 60, done. remote: Counting objects: 100% (60/60), done. remote: Compressing objects: 100% (40/40), done. remote: Total 560 (delta 38), reused 42 (delta 20), pack-reused 500 Receiving objects: 100% (560/560), 76.92 KiB | 380.00 KiB/s, done. Resolving deltas: 100% (351/351), done. Tapped 6 formulae (30 files, 128.8KB). ==> Installing cloudflared from cloudflare/cloudflare ==> Downloading https://packages.argotunnel.com/dl/cloudflared-2020.11.11-darwin ######################################################################## 100.0% Error: Your CLT does not support macOS 11. It is either outdated or was modified. Please update your CLT or delete it if no updates are available. Update them from Software Update in System Preferences or run: softwareupdate --all --install --force If that doesn't show you an update run: sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install Alternatively, manually download them from: https://developer.apple.com/download/more/.
このため、エラーメッセージにある順番でコマンドを実行しました。
softwareupdate --all --install --force sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install
そして再度brewコマンドを用いてcloudflaredをインストールします。
brew install cloudflare/cloudflare/cloudflared [https://github.com/WassimBenzarti/colab-ssh/blob/master/docs/assets/launch_ssh_cloudflared.jpg?raw=true:image=https://github.com/WassimBenzarti/colab-ssh/blob/master/docs/assets/launch_ssh_cloudflared.jpg?raw=true]
5. ~/.ssh/configに下記を追加します。
Host *.trycloudflare.com HostName %h User root Port 22 ProxyCommand /usr/local/Cellar/cloudflared/2020.11.11/bin/cloudflared access ssh --hostname %h #環境設定私の環境には私の環境を入力しました。
6. google colab画面に戻り、下記のSSH TERMINALを確認します。
7. sshをterminalで実行
colab上の下記コマンドをペーストして、terminal上で実行します。
ssh attachments-forums-xxxx.com
パスワードを聞かれますが、手順2.で設定したパスワード(今回はhogehoge)を入力します。
vscodeの場合
手順7.の代わりにVSCode Remote SSHを利用します。 Ctrl+Shift+P を実行し、 "Connect to Host..."に下記ホスト名をペーストし実行します。
attachments-forums-xxxx.com
追記 2021.03.22
下記ツールを利用することで対応できる様です。
お役に立てましたら幸いです。