The local machine Google Colab connects to the remote server through SSH

1. Scenario Description

My own notebook configuration is too rubbish, and I want to use the school's deep learning server to run programs on Colab.

2. Environment description

Remote server (Ubuntu):

  1. Use pip to install jupyter notebook and jupyter_http_over_ws expansion package (the premise is python environment and pip)
pip install notebook
pip install jupyter_http_over_ws
jupyter serverextension enable --py jupyter_http_over_ws
  1. Install and start ssh service
sudo apt-get install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

Check whether the ssh service is running normally:

sudo systemctl status ssh
  1. An account and IP address are required.
    Suppose the account name is username.
    The IP address can ifconfigbe found , here it is assumed to be 192.168.0.1.

Local machine (notebook):

  1. SSH connection tool
    Mac OS has its own SSH connection, you only need to enter the account number and IP ssh [email protected]here .

There are many connection tools for Windows SSH, such as Putty, Xshell, Bitvise, so I won’t go into details here. Just be able to connect to the remote server with SSH.

  1. As long as Google Colab
    can run

3. Butt!

1. Open jupyter notebook on the remote server and allow Colab to access it.

jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com'  --port=8888  --NotebookApp.port_retries=0

After running successfully, the command line will generate two links, the format is similar to:

http://localhost:8888/?token=abc123

Copy this link for later use.

2. SSH to the server on the local machine

# 将 <PORT> 替换为在上述步骤中选择的端口号 8888
# 将 <REMOTE_USER> 替换为远程服务器用户名 username
# 将 <REMOTE_HOST> 替换为您的远程服务器地址 192.168.0.1

ssh -L 8888:localhost:<PORT> <REMOTE_USER>@<REMOTE_HOST>

In our example it would be

ssh -L 8888:localhost:8888 [email protected]

3. Open Colab

Select local runtime.
insert image description here
Enter the link http://localhost:8888/?token=abc123 generated on the remote server in the first step. (It’s a trick here, set the ports of the two machines to be the same, so you don’t need to change the url)

At this point, you should be able to run the program on the local colab using the remote server.

REFERENCE

[1] https://www.cyberciti.biz/faq/ubuntu-linux-install-openssh-server/

[2] https://docs.anaconda.com/anaconda/user-guide/tasks/remote-jupyter-notebook/

[3] https://research.google.com/colaboratory/local-runtimes.html

that's all.

Guess you like

Origin blog.csdn.net/qq_41608408/article/details/128349790