假设服务器上已经安装好了 Anaconda3 + Jupyter之后。
$ jupyter-notebook --generate-config
现在最近版本的jupyter可以直接用以下命令:
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
这里只需你输入密码确认,然后他会自动帮你把生成含有密码的hash码输入jupyter_notebook_config.json文件。
c.NotebookApp.ip = ‘*‘
c.NotebookApp.allow_root = True
c.NotebookApp.port = 8888
如果内网访问,则直接使用:jupyter-notebook
;如果是外网访问,则继续往下看。
$ jupyter notebook --no-browser --port=8889 --ip=127.0.0.1
$ ssh -N -f -L localhost:8888:localhost:8889 -p 22 remote_user@remote_host
这里会需要你输入你的远程服务器用户的密码,输入成功后。
在本地浏览器网址栏输入http://127.0.0.1:8888, 然后你就可以看到熟悉的jupyter-notebook界面了。
由于jupyter notebook访问的时候,默认使用了anaconda的base环境,这里就需要更换环境。
具体方式如下:
(base) $ conda activate your_env
(your_env) $ conda install nb_conda_kernels
Collecting package metadata (current_repodata.json): done
Solving environment: done
python -m ipykernel install --user --name 环境名称 --display-name "显示的名称"
大功告成
关于Jupyter notebook远程连接服务器踩坑记-Caliber-知乎
远程访问服务器Jupyter Notebook的两种方法-ibunny-简书
原文:https://www.cnblogs.com/Tsingwaa/p/15127538.html