远程调用服务器的jupyter notebook设置
具体实现代码如下
(base) hu@ubuntu-server:~$ jupyter notebook --generate-config
(base) hu@ubuntu-server:~$ ipython
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: ****
Verify password: ****
Out[2]: 'sha1:41357d7305ce:f176435275b8245bb5409fbde417cd05efcf4bc4'
# 输出的一串notebook 登录的hash值,需要记住
# Ctrl + D 退出ipython
(base) hu@ubuntu-server:~$ vim ~/.jupyter/jupyter_notebook_config.py
# 添加下面的几句到jupyter_notebook_config.py,保存退出
c.NotebookApp.allow_remote_access = True # 允许远程访问
c.NotebookApp.ip = '*' # 设置访问的IP地址,*为所有
c.NotebookApp.open_browser = False # 不启动浏览器
c.NotebookApp.password = u'sha1:41357d7305ce:f176435275b8245bb5409fbde417cd05efcf4bc4' # notebook登录密码的hash值
c.NotebookApp.port = 9000 # 设置访问端口, 默认是8888 ,冲突的话需要修改
# 在服务器上运行jupyter notebook
(base) hu@ubuntu-server:~$ jupyter notebook
# 本地重新开一个终端
(pyt38) hu@hu-hp:~$ ssh -N -f -L localhost:8000:localhost:9000 hu@172.20.167.167
# 9000是在jupyter_notebook_config.py设置的访问端口,8000是本地转换的端口,服务器地址:hu@172.20.167.167
# 之后在本地的浏览器输入:localhost:8000 即可进入登录页面,输入之前设置的密码就可进入jupyter notebook