1、生成自己的jupyter配置文件:jupyter_notebook_config.py
jupyter 默认的配置文件一般在
~/.jupyter/jupyter_notebook_config.py
里面有各种jupyter的参数,咱们生成一个自己的配置文件。将这个默认的配置文件复制到指定目录下
cp ~/.jupyter/jupyter_notebook_config.py your_path
2、设置密码,并生成加密hash密码
在终端输入ipython
创建一个秘钥
ipython
然后输入以下命令。会让你输入密码和确认密码(PS:输入密码的时候不会显示)。
from notebook.auth import passwd
passwd()
Enter password:
Verify password:
Out[2]: 'sha1:vwucvijqy318odiqw:336194696f169fd'
exit()
生成的那一大串字符,就是加密的密码,需要写到配置文件jupyter_notebook_config.py中。
3、修改配置文件
编辑修改第1步复制的配置文件:your_path/jupyter_notebook_config.py
vim your_path/jupyter_notebook_config.py
找到如下参数,并进行修改
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:vwucvijqy318odiqw:336194696f169fd'
password的地方,写的就是第2步生成的加密hash密码。
4、远程启动jupyter
终端输入以下命令
your_path/bin/python your_path/bin/jupyter-notebook --config=your_path/jupyter_notebook_config.py --allow-root
your_path/bin/python 指定Python环境
your_path/bin/jupyter-notebook 指定jupyter
–config=your_path/jupyter_notebook_config.py 指定配置文件。
终端会输出一系列日志,其中有http://开头的一个网址,复制该网址在浏览器中,回车,会显示输入密码,输入设置的密码(注意不是hash密码,是没加密的密码)即可远程打开jupyter。
5、报错
如果出现以下报错
socket.gaierror: [Errno -2] Name or service not known
原因:由于远程打开的时候,没有设置allow_remote_access=True
解决办法:打开配置文件jupyter_notebook_config.py,进行修改。
vim your_path/jupyter/jupyter_notebook_config.py
找到c.NotebookApp.allow_remote_access,修改成如下:
c.NotebookApp.allow_remote_access=True