Jupyter Notebook开启远程连接

Jupyter Notebook开启远程连接

前言

刚刚接触Linux,用Vim这种编辑器实在用不习惯啊。。。
只好安装了一个Jupyter Notebook,开启远程连接。

准备工作

使用命令行安装Jupyter Notebook,直接输入“pip3 install jupyter”,之后耐心等待就行了。

如果安装完之后,输入“jupyter notebook”,可以正常启动,就算是安装成功了。

开始配置远程连接

1.在终端输入“jupyter notebook --generate-config --allow-root”,就能生成Jupyter Notebook的配置文件。这个配置文件在“~/.jupyter/”文件夹内。
Jupyter Notebook开启远程连接
2.在终端输入“ipython”,打开ipython。

在打开的ipython中输入“from notebook.auth import passwd”,之后再输入“passwd()”,之后会提示要输入密码,这个密码是远程连接时的登陆密码。
Jupyter Notebook开启远程连接
将生成的“sha1:……”这串文字复制保存下来,这是密码的hash值。

3.使用cd命令切换到“~/.jupyter/”文件夹内,输入“vim jupyter_notebook_config.py”,开始配置远程连接。
Jupyter Notebook开启远程连接
对配置文件里面的以下值做出修改:

(1)允许用户root运行:
c.NotebookApp.allow_root =True
Jupyter Notebook开启远程连接
(2)修改服务监听地址:
c.NotebookApp.ip = ‘*’
Jupyter Notebook开启远程连接
(3)是否打开浏览器:
c.NotebookApp.open_browser = False

(4)hash值(将生成的“sha1:……”填入):
c.NotebookApp.password = ‘sha1:……’

(5)服务监听的端口:
c.NotebookApp.port = 8888
Jupyter Notebook开启远程连接
注意要去掉前面的“#”。

这就行啦!

使用过程

在终端输入“jupyter notebook”,启动Jupyter Notebook。

在浏览器输入“ip地址:端口号”,例如:192.168.0.10:8888。

第一次连接,需要输入密码,就是刚才自己设置的那个。

之后就能打开Jupyter Notebook啦!
Jupyter Notebook开启远程连接