Ubuntu 16.04 LTS 配置 Jupyter notebook 为服务器

原材料:

Ubuntu 16.04 LTS 64bit

已经配置好 IPython 和 Jupyter (安装步骤可以参照:http://www.cnblogs.com/McKean/p/6194977.html)

一、使用OpenSSL产生 *.key 和 *.pem 密钥

cd ~/.jupyter 切换到.jupyter目录

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem

成功的话,会在.jupyter目录下面产生 mykey.key 和 mycert.pem 两个文件

注意:这个OpenSSL是可选的,即使不适用OpenSSL也可以配置 jupyter使得局域网里面可以访问的。

二、设置密钥的sha1码

可以在IPython里面输入一下命令并按照提示输入密码,即可产生你需要密码对应的sha1值。

In [1]: from notebook.auth import passwd

In [2]: passwd()
c:\python27\lib\getpass.py:92: GetPassWarning: Can not control echo on the termi
nal.
  return fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Enter password: 12345678
Warning: Password input may be echoed.
Verify password: 12345678
Out[2]: 'sha1:c88810a822cf:2a10d54101bf6b326351c15f0c7b9fede372ef23'

  

三、产生并配置 jupyter_notebook_config.py 文件

使用 ls 命令查看.jupyter 目录下面有没有 jupyter_notebook_config.py 文件

如果没有,则使用 jupyter notebook --generate-config 命令产生一个

默认jupyter_notebook_config.py的配置都使用#注释掉,下面需要开启所需要的命令。

这里password 一项要使用前面产生的sha1值## The full path to an SSL/TLS certificate file.c.NotebookApp.certfile = u'/home/peter/.jupyter/mycert.pem

## The IP address the notebook server will listen on.
c.NotebookApp.ip = '192.168.242.139'
 
#  The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = u'sha1:96d749b4e109:17c2968d3bc899fcd41b87eb0853a42ceb48c521'
 
## The port the notebook server will listen on.
c.NotebookApp.port = 8888

c.NotebookApp.open_browser = False

  

配置Jupyter notebook的默认目录

c.NotebookApp.notebook_dir = u'/home/peter/Git/MatlabMisc/Jupyter'

  

四、启动Jupyter notebook

在~/.jupyter目录下,输入下面命令即可
sudo jupyter notebook --certfile=mycert.pem --keyfile mykey.key

然后在其他机器上,输入 https://192.168.242.139:8888 (这里的ip是根据你自己的环境和在jupyter_notebook_config.py 文件配置的ip)

再输入密码即可

 

posted @ 2017-02-12 17:26  PACHEL35  阅读(6129)  评论(0编辑  收藏  举报