配置Jupyter Lab的密码并实现局域网访问

主要重点:
把配置设置中的c.ServerApp.password改为调用c.PasswordIdentityProvider.hashed_password,以符合官方的要求

  1. 安装Anaconda将自动安装好jupyter,包括notebook和lab

  2. 安装Node
    安装Node.js的目的是在登录时有更有好的界面。
    linux安装Node.js教程

  3. 生成配置文件

    $ jupyter notebook --generate-config
    Writing default config to: ~/.jupyter/jupyter_notebook_config.py
    

    虽然是notebook的配置文件,但是实测lab也通用,如果没有反应,可以考虑使用jupyter lab --generate-config

  4. 设置密码

    li@lab:~$ python
    >>>from jupyter_server.auth import passwd;
    >>>passwd()
    Enter password: 
    Verify password: 
    'argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuxxxxxxxxxxxxxxxx'
    

    记住生成的秘钥,形如:
    argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuuxxxxxxxxxxxxxxxx

  5. 修改配置文件

    • 老版本的配置,已经过时了:

      c.NotebookApp.ip = '*' # 你的服务器的IP地址,一般是静态地址
      c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuuxxxxxxxxxxxxxxxx' # 这个是刚要保存的秘钥
      c.NotebookApp.open_browser = False
      c.NotebookApp.port = 8890    #端口,可以随意指定
      c.NotebookApp.allow_remote_access = True
      
    • 新版本要用c.ServerApp

      c.ServerApp.ip = '*'  # 允许访问此服务器的 IP,星号表示任意 IP
      # 这个是刚保存的秘钥
      c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuuxxxxxxxxxxxxxxxx'
      c.ServerApp.open_browser = False # 运行时不打开本机浏览器
      c.ServerApp.port = 8890    #端口,可以随意指定 不与系统其他端口冲突即可
      c.ServerApp.allow_remote_access = True  #允许远程访问
      c.ServerApp.root_dir = '/home/li/JupyterCode' # 默认初始目录,你也可以改为/home
      
    • 就算这样,在使用jupyter lab命令运行时会有报错:

      ServerApp.password config is deprecated in 2.0. Use PasswordIdentityProvider.hashed_password.
      

      因此要把c.ServerApp.password改为调用c.PasswordIdentityProvider.hashed_password

      # ServerApp.password:DEPRECATED in 2.0. 
      # Use PasswordIdentityProvider.hashed_password
      c.PasswordIdentityProvider.hashed_password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuuxxxxxxxxxxxxxxxx''
      
    • 综上:

      c.ServerApp.ip = '*'  # 允许访问此服务器的 IP,星号表示任意 IP
      # 这个是刚保存的秘钥
      c.PasswordIdentityProvider.hashed_password = u'argon2:$argon2id$v=19$m=10240,t=10,p=8$yb6aBw2p5is+gReTnMuHiQ$+AJZuxNNZ9YBSmKywrxMz+SYb+46NFKqwoC1AbWNSjs'
      c.ServerApp.open_browser = False # 运行时不打开本机浏览器
      c.ServerApp.port = 8890    #端口,可以随意指定 不与系统其他端口冲突即可
      c.ServerApp.allow_remote_access = True  #允许远程访问
      c.ServerApp.root_dir = '/home/li/JupyterCode' # 默认初始目录,你也可以改为/home
      
  6. 启动并进入Jupyter
    Jupyter lab
    http://192.168.50.138:8890

  7. 可以通过screen命令,打开一个后台的terminal,开启后将这个terminal隐藏(detach)从而不影响前台工作

    screen -R jupyter
    jupyter lab
    Ctrl+A→松开后→再按D
    

    详见:Linux终端命令神器–Screen命令详解。助力Linux使用和管理

参考:远程服务器ubuntu安装Jupyter Lab详细教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值