为了跑深度学习模型,决定租用带有GPU的远程服务器来进行训练。使用ssh连接服务器,在本地连接服务器Jupyter lab来进行代码编写与运行。

SSH远程连接服务器

# 安装net-tools 用于查看ip地址
sudo apt install net-tools
# 查看ip地址
ifconfig
# 安装vim
sudo apt install vim
# 配置ssh
sudo vim /etc/ssh/sshd_config
# 添加新内容
PermitRootLogin yes
# 重启ssh
sudo service ssh restart

在本地终端输入

ssh root@ip # 输入密码即可访问

Jupyter Notebook配置

# 安装 jupyter
pip install jupyter
# 在安装jupyter lab, 比jupyter更好用,共享配置文件
pip install jupyterlab
# 建立配置文件
jupyter lab --generate-config

# 添加内容
c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8886 # 默认为8888,建议不要和本地jupyter端口相同
c.NotebookApp.allow_remote_access = True
c.NotebookApp.notebook_dir = '/'

# 启动jupyter lab
jupyter lab

image-20210417021854348

这时候访问不了jupyter lab,因为127.0.0.1是localhost

image-20210417021801488

在本地映射端口

ssh -L8886:localhost:8886 root@ip
# 输入密码

再次点击上面的链接即可访问

image-20210417022011423