1.总览
- 将本地密钥创建到云服务器
- 防火墙规则
- jupyter
2.行动
2.1 将本地密钥创建到云服务器

图片.png

图片.png
# 在linux上或者windows的cmd里
# -t 指定密钥类型 -C 密钥的备注
ssh-keygen -t rsa -C "xxxxx"

图片.png

图片.png

图片.png

图片.png

图片.png
创建自己的用户,假设这里我创建的是misaki
# -m 从家目录中创建 -s指定shell 最后的为要创建的用户名
sudo useradd -m -s /bin/bash misaki
之后修改misaki的权限
sudo EDITOR=vim visudo

图片.png
然后将ubuntu的密钥复制到misaki目录下
mkdir /home/misaki/.ssh
cp ~/.ssh/authorized_keys /home/misaki/.ssh/authorized_keys
之后就可以用misaki来登录
ssh misaki@ip
2.2 防火墙规则
这里我是把jupyter的端口设置成8887,所以开放8887端口

图片.png
2.3 jupyter
2.3.1 安装miniconda3
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
2.3.2 更新pip

图片.png
2.3.3 安装jupyter和d2l
pip install jupyter d2l
2.3.4 配置jupyter notebook
先生成密钥
python
from notebook.auth import passwd
passwd()
....
生成配置文件
jupyter notebook --generate-config
vim ~/.jupyter/jupyter_notebook_config.py
在最后部分加上
c.NotebookApp.password = '....'
#刚才的哈希密码
c.NotebookApp.port = 8887
#指定jupyter lab 运行端口,写一个不冲突的端口即可
c.NotebookApp.allow_remote_access = True
# 允许远程访问
c.NotebookApp.ip='*'
# 就是设置所有ip皆可访问
c.NotebookApp.open_browser = False
# 禁止自动打开浏览器
2.3.4 后台运行jupyter
nohup jupyter notebook&

图片.png
2.3.1 安装主题、拓展
主题
pip install --upgrade jupyterthemes
#查看拥有的主题
jt -l
#切换主题
jt -t <主题名> -T -N
拓展
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
3.Q&A
有时候save error怎么办?
利用ssh的端口转发,绑定到本地端口
ssh -L localhost:8888:localhost:8888 jupyter的host -N -f
# 关闭
pkill -f "ssh -L localhost:8888:localhost:8888 jupyter的host -N -f"
- 前一个localhost:8888 -> 本机地址+端口
- 后一个localhost:8888 -> 远程jupyter的localhost + 端口
- -L 绑定本地ip+端口到远端ip+端口
- -N 这次的ssh只做端口转发
- -f ssh在后台运行
在jupyter的运行notebook中怎样设置/清除代理?
用os包
import os
# 设置代理
os.environ["http_proxy"] = xxxx
os.environ["https_proxy"] = xxxx
# 清除代理
os.unsetenv("http_proxy")
os.unsetenv("https_proxy")
jupyter lab config
# 在最后面加
c.ServerApp.password = xxx
c.ServerApp.open_browser = False
c.ServerApp.port = 8891
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '*'
jupyter lab 中文界面
pip install jupyterlab-language-pack-zh-CN
jupyter lab无法用tqdm
pip install ipywidgets
安装node
linux下二进制包
在jupyter extentions安装

图片.png
防止断开
# ~/.ssh/config
Host hostname
HostName 172.xx.xx.xx
User xxxx
ServerAliveInterval 60
ServerAliveCountMax 5
jupyter lab设置密码
jupyter server password