如何配置Jupyter notebook进行远程访问并实现SSL加密?

2026-05-27 01:421阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计837个文字,预计阅读时间需要4分钟。

如何配置Jupyter notebook进行远程访问并实现SSL加密?

Jupyter Notebook 的安装方法在此不做详细阐述,可参考 Jupyter 官方网站提供的步骤:[Jupyter 官方安装指南](http://jupyter-notebook.readthedocs.io/en/latest/public_server.)。以下将讨论如何在 Jupyter Notebook 中配置远程访问,包括 SSL 加密。

1. 远程访问配置: - 确保你的 Jupyter Notebook 服务器已启动。 - 在终端中运行以下命令来启动 Jupyter Notebook 的 HTTP 服务器,并允许远程访问: bash jupyter notebook --ip='0.0.0.0' --port=8888 - 这将启动一个服务器,允许来自任何 IP 地址的连接,并监听 8888 端口。

2. SSL 加密配置: - 为了安全起见,可以使用 SSL 加密来保护你的连接。 - 你需要生成 SSL 证书和私钥。可以使用 OpenSSL 来生成自签名证书: bash openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem - 将生成的 `mycert.pem` 文件放置在 Jupyter Notebook 的工作目录中。 - 在启动 Jupyter Notebook 服务器时,使用 `--certfile` 和 `--keyfile` 参数指定证书和私钥: bash jupyter notebook --ip='0.0.0.0' --port=8888 --certfile=mycert.pem --keyfile=mykey.pem - 现在你可以通过 HTTPS 连接到你的 Jupyter Notebook 服务器,确保使用 `https://` 前缀。

jupyter notebook的安装在这里都不赘述

可以参考jupyter官网的步骤

如何配置Jupyter notebook进行远程访问并实现SSL加密?

jupyter-notebook.readthedocs.io/en/latest/public_server.html

这里讨论下jupyter notebook里面的远程访问配置以及SSL加密

1. 远程访问配置

jupyter notebook --generate-config

这个命令会在当前用户的 ~/.jupyter/ 文件夹下面生成一个 jupyter_notebook_config.py 文件

jupyter notebook password

可以生成你需要的远程密码,自己填一下就好,密码会直接输出到 jupyter_notebook_config.json 文件

接下来编辑 jupyter_notebook_config.py 文件中的以下几个部分:

# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999

最后一个端口号根据自己的实际情况进行设置

2. SSL加密配置

自己建一个文件夹或者干脆在~/.jupyter/ 文件夹下面执行下面命令:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem

同时编辑 jupyter_notebook_config.py

# browser auto-opening
c.NotebookApp.certfile = u'路径名/mycert.pem'

接下来启动

jupyter notebook

注意在访问时要使用https协议

补充知识:jupyter notebook 中打开ipynb文件时报错 NameError: name 'true' is not defined

在jupyter notebook 中打开ipynb文件时报错:

File "e:\python36\lib\site-packages\traitlets\config\loader.py", line 457, in load_config self._read_file_as_dict() File "e:\python36\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict py3compat.execfile(conf_filename, namespace) File "e:\python36\lib\site-packages\ipython_genutils\py3compat.py", line 198, in execfile exec(compiler(f.read(), fname, 'exec'), glob, loc) File "C:\Users\xiaoqiu\.ipython\profile_default\ipython_config.py", line 513, in <module> c.Completer.greedy = true NameError: name 'true' is not defined

resolution:

在执行了ipython profile create 命令(激活自动补全的功能)之后 C:\Users\xiaoqiu\.ipython\profile_default生成了两个文件

需要修改ipython_config.py文件修改如下三个参数

以上这篇Jupyter notebook 远程配置及SSL加密教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计837个文字,预计阅读时间需要4分钟。

如何配置Jupyter notebook进行远程访问并实现SSL加密?

Jupyter Notebook 的安装方法在此不做详细阐述,可参考 Jupyter 官方网站提供的步骤:[Jupyter 官方安装指南](http://jupyter-notebook.readthedocs.io/en/latest/public_server.)。以下将讨论如何在 Jupyter Notebook 中配置远程访问,包括 SSL 加密。

1. 远程访问配置: - 确保你的 Jupyter Notebook 服务器已启动。 - 在终端中运行以下命令来启动 Jupyter Notebook 的 HTTP 服务器,并允许远程访问: bash jupyter notebook --ip='0.0.0.0' --port=8888 - 这将启动一个服务器,允许来自任何 IP 地址的连接,并监听 8888 端口。

2. SSL 加密配置: - 为了安全起见,可以使用 SSL 加密来保护你的连接。 - 你需要生成 SSL 证书和私钥。可以使用 OpenSSL 来生成自签名证书: bash openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem - 将生成的 `mycert.pem` 文件放置在 Jupyter Notebook 的工作目录中。 - 在启动 Jupyter Notebook 服务器时,使用 `--certfile` 和 `--keyfile` 参数指定证书和私钥: bash jupyter notebook --ip='0.0.0.0' --port=8888 --certfile=mycert.pem --keyfile=mykey.pem - 现在你可以通过 HTTPS 连接到你的 Jupyter Notebook 服务器,确保使用 `https://` 前缀。

jupyter notebook的安装在这里都不赘述

可以参考jupyter官网的步骤

如何配置Jupyter notebook进行远程访问并实现SSL加密?

jupyter-notebook.readthedocs.io/en/latest/public_server.html

这里讨论下jupyter notebook里面的远程访问配置以及SSL加密

1. 远程访问配置

jupyter notebook --generate-config

这个命令会在当前用户的 ~/.jupyter/ 文件夹下面生成一个 jupyter_notebook_config.py 文件

jupyter notebook password

可以生成你需要的远程密码,自己填一下就好,密码会直接输出到 jupyter_notebook_config.json 文件

接下来编辑 jupyter_notebook_config.py 文件中的以下几个部分:

# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999

最后一个端口号根据自己的实际情况进行设置

2. SSL加密配置

自己建一个文件夹或者干脆在~/.jupyter/ 文件夹下面执行下面命令:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem

同时编辑 jupyter_notebook_config.py

# browser auto-opening
c.NotebookApp.certfile = u'路径名/mycert.pem'

接下来启动

jupyter notebook

注意在访问时要使用https协议

补充知识:jupyter notebook 中打开ipynb文件时报错 NameError: name 'true' is not defined

在jupyter notebook 中打开ipynb文件时报错:

File "e:\python36\lib\site-packages\traitlets\config\loader.py", line 457, in load_config self._read_file_as_dict() File "e:\python36\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict py3compat.execfile(conf_filename, namespace) File "e:\python36\lib\site-packages\ipython_genutils\py3compat.py", line 198, in execfile exec(compiler(f.read(), fname, 'exec'), glob, loc) File "C:\Users\xiaoqiu\.ipython\profile_default\ipython_config.py", line 513, in <module> c.Completer.greedy = true NameError: name 'true' is not defined

resolution:

在执行了ipython profile create 命令(激活自动补全的功能)之后 C:\Users\xiaoqiu\.ipython\profile_default生成了两个文件

需要修改ipython_config.py文件修改如下三个参数

以上这篇Jupyter notebook 远程配置及SSL加密教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。