
配置Jupyter Lab的密码并实现局域网访问
配置Jupyter Lab的密码并实现局域网访问
·
主要重点:
把配置设置中的c.ServerApp.password
改为调用c.PasswordIdentityProvider.hashed_password
,以符合官方的要求
-
安装Anaconda将自动安装好jupyter,包括notebook和lab
-
安装Node
安装Node.js的目的是在登录时有更有好的界面。
linux安装Node.js教程 -
生成配置文件
$ jupyter notebook --generate-config Writing default config to: ~/.jupyter/jupyter_notebook_config.py
虽然是notebook的配置文件,但是实测lab也通用,如果没有反应,可以考虑使用
jupyter lab --generate-config
-
设置密码
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
-
修改配置文件
-
老版本的配置,已经过时了:
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
-
-
启动并进入Jupyter
Jupyter lab
http://192.168.50.138:8890
-
可以通过
screen
命令,打开一个后台的terminal,开启后将这个terminal隐藏(detach)从而不影响前台工作screen -R jupyter jupyter lab Ctrl+A→松开后→再按D
更多推荐
所有评论(0)