准备工作

  • 使用终端软件登录服务器
  • 下载jupyter notebook pip install jupyter notebook
  • 生成配置文件 jupyter notebook --generate-config 或者该文件已生成在/.jupyter/

生成密钥

输入 ipython打开ipython

In[1]:from notebook.auth import passwd
In[2]:passwd()
Enter password:    # 输入密码
Verify password:    # 确认密码
Out[2]:'sha1:xxxxx'    # 这是一段密钥 复制下来备用

修改配置文件

在服务器用户目录下打开配置文件
vim .jupyter/jupyter_notebook_config.py
按i键进入insert模式 输入以下内容

c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:xxx'    # 刚刚复制的密钥
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888    #随便指定一个端口,但是要记住
c.NotebookApp.allow_remote_access = True

启动jupyter notebook
jupyter notebook

本地连接

下面进行端口映射
先在本地终端输入
ssh -N -f -L localhost:xxxx:localhost:8888 -p 端口号 username@远程服务器IP
其中xxxx自定义为稍后本地要输入的port
8888要和配置文件中的port一致
端口号为远程服务器的端口号
username为远程服务器的用户名

最后 在浏览器地址栏输入 localhost:xxxx即可打开jupyter notebook
输入在生成密钥步骤中的password即可登录

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐