Linux安装 Jupyter Notebook 并配置任意IP密码访问

本文详细介绍在Linux环境下安装及配置Jupyter Notebook的过程,包括如何生成配置文件、设置访问密码、更改端口号以及开放任意IP访问等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux安装 Jupyter Notebook 并配置任意IP密码访问

1. 下载安装包

https://www.anaconda.com/products/individual

在这里插入图片描述
我这里下载Linux 64位版本的
也可以在终端直接输入以下命令进行下载:

wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh

2. 安装

sh Anaconda3-2020.02-Linux-x86_64.sh

q回车

Welcome to Anaconda3 2020.02
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

按Enter

Anaconda reserves all rights not expressly granted to you in this Agreement.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the followi
ng conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following dis

Do you accept the license terms? [yes|no]
[no] >>>

输入yes回车

Anaconda3 will now be installed into this location:
/home/jupyter/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

按Enter

Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>>

输入yes回车
在终端输入以下两条命令

touch ~/.condarc
source ~/.bashrc

在命令行输入jupyter notebook 即可进入notebook
Ctrl + C停止运行

3. 配置

3.1 生成jupyter配置文件

jupyter notebook --generate-config --allow-root

此时会返回给我们配置文件的位置
Writing default config to: /home/jupyter/.jupyter/jupyter_notebook_config.py

3.1 生成哈希密码

$ ipython

Python 3.7.6 (default, Jan  8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from notebook.auth import passwd

In [2]:passwd()
Enter password:
Verify password:
Out[2]: 'sha1:9b54xxxxd0d5:694b082faxxxc1862f969170f211xxx5b9xxxxee' 

得到一串哈希密码

3.3 修改配置文件

打开3.1中生成的这个配置文件

vi ~/.jupyter/jupyter_notebook_config.py
  • 修改密码
    找到#c.NotebookApp.password = ''
    去掉前面的#,在引号中输入刚才生成的哈希密码

  • 更改端口
    c.NotebookApp.port = 8888,端口改为8888

  • 任何IP可访问
    修改:#c.NotebookApp.ip = 'localhost'
    变为:c.NotebookApp.ip = '*'

ESC+:wq保存退出。

3.4 配置文件中的其他可配置选项

c.NotebookApp.notebook_dir ='' #配置jupyter文件夹的目录

### 如何在Linux云服务器上安装配置Jupyter Notebook #### 准备环境 为了确保顺利安装配置Jupyter Notebook,在开始之前需确认已具备适当的操作系统版本以及必要的依赖项。通常推荐使用较新的稳定版Linux发行版,比如CentOS 7或更新版本[^4]。 #### 使用pip安装Jupyter Notebook 通过`pip`工具来安装最新版本的Jupyter Notebook是一个常见做法。在此之前建议先升级pip至最新版本以避免潜在兼容性问题: ```bash pip install --upgrade pip ``` 接着执行如下命令完成Jupyter Notebook本身的安装: ```bash pip install jupyter ``` 这一步骤会自动处理所有必需的Python包依赖关系[^1]。 #### 初始化与启动服务 首次运行时可以通过下面这条简单的指令来进行初始化启动Jupyter Notebook的服务端程序: ```bash jupyter notebook --generate-config ``` 上述操作会在用户的家目录下创建默认配置文件`.jupyter/jupyter_notebook_config.py`用于后续自定义设置[^2]。 #### 修改配置文件 编辑生成好的配置文件可以调整诸如监听地址、端口号等重要参数以便更好地适应实际应用场景需求。对于希望开放给外部网络访问的情况来说,修改绑定IP为0.0.0.0允许来自任意位置连接请求;同时指定固定端口有助于简化防火墙规则管理。另外开启密码保护机制也是保障数据安全性的必要措施之一[^3]。 #### 处理可能遇到的问题 如果在整个过程中遇到了权限不足或者其他技术难题,则可以根据具体错误提示信息查找对应的解决方案。常见的解决办法包括但不限于更改文件夹读写属性、重新加载内核模块或是调整SELinux策略等等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会飞的果粒橙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值