GCP深度学习VM镜像Jupyter自动启动但无登录Token问题求助
解决GCP深度学习VM镜像中Jupyter Notebook的自动启动与登录问题
GCP提供的Deep Learning VM镜像默认通过systemd服务托管Jupyter Notebook,这是你遇到一系列异常现象的核心原因,以下是针对性解决方法:
获取登录Token/设置自定义密码
- 直接从服务日志提取Token:
在日志输出里搜索sudo journalctl -u jupyter.servicetoken=字段,即可找到登录用的Token。 - 设置固定密码(长期使用更方便):
- 生成密码哈希:在任意用户下执行
jupyter notebook password,按提示输入密码后,命令会输出哈希值的存储路径(一般是~/.jupyter/jupyter_notebook_config.json)。 - 找到系统级Jupyter配置文件:
sudo find / -name jupyter_notebook_config.py - 编辑该配置文件,添加或修改以下行(替换为你生成的哈希值):
c.NotebookApp.password = 'sha1:xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' - 重启Jupyter服务生效:
sudo systemctl restart jupyter.service
- 生成密码哈希:在任意用户下执行
查看运行中的Jupyter实例
jupyter notebook list仅能显示当前用户启动的实例,而系统托管的Jupyter由专用用户运行,你可以通过以下方式查看:
- 查看systemd服务状态:
sudo systemctl status jupyter.service - 切换到服务运行用户后执行列表命令(先通过
ps aux | grep jupyter找到运行用户,通常是jupyter或root):sudo -u jupyter jupyter notebook list
停止自动重启的Jupyter进程
直接杀进程会触发systemd的自动重启机制,正确停止方式:
- 临时停止服务:
sudo systemctl stop jupyter.service - 禁止开机自动启动:
sudo systemctl disable jupyter.service
手动启动独立的Jupyter实例
先停掉系统托管的服务,再手动启动个人实例(建议换端口避免冲突):
sudo systemctl stop jupyter.service # 切换到你的工作用户 su - your_username # 启动Jupyter Lab或Notebook,指定端口 jupyter lab --port 8889
内容的提问来源于stack exchange,提问作者Enes Kuz
相关产品推荐
相关产品推荐

