远程访问虚拟机 jupyter notebook

在服务器上配置jupyter, 方便咱们远程登陆.python

第一步:安装jupyter, pip3 install jupyter (此处使用的是python3)shell

第二步:生成配置文件jupyter notebook --generate-configubuntu

gz@ubuntu:~$ cd .jupyter/
gz@ubuntu:~/.jupyter$ ll
total 12
drwxr-xr-x  2 gz gz 4096 Sep  3 14:56 ./
drwxr-xr-x 36 gz gz 4096 Sep  4 11:28 ../
-rw-r--r--  1 gz gz   26 Sep  3 14:56 migrated
gz@ubuntu:~/.jupyter$ jupyter notebook --generate-config
jupyter: command not found
gz@ubuntu:~/.jupyter$ workon py3_face
(py3_face) gz@ubuntu:~/.jupyter$ jupyter notebook --generate-config
Writing default config to: /home/gz/.jupyter/jupyter_notebook_config.py
(py3_face) gz@ubuntu:~/.jupyter$ ll
total 48
drwxr-xr-x  2 gz gz  4096 Sep  4 11:35 ./
drwxr-xr-x 36 gz gz  4096 Sep  4 11:28 ../
-rw-rw-r--  1 gz gz 33341 Sep  4 11:35 jupyter_notebook_config.py
-rw-r--r--  1 gz gz    26 Sep  3 14:56 migrated
(py3_face) gz@ubuntu:~/.jupyter$

第三步:生成密钥 打开python3vim

>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'sha1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
>>>

修改配置文件浏览器

vim + ~/.jupyter/jupyter_notebook_config.py

添加内容以下:服务器

c.NotebookApp.ip="192.168.xxx.xxx"
c.NotebookApp.password = u"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"   # 刚才复制的那个密文
c.NotebookApp.open_brower = False # # 禁止自动打开浏览器
c.NotebookApp.port = 8888 #随便指定一个端口

这里注意:c.NotebookApp.ip='104.222.1.1',这里应该填写你服务器的ip,网上的所有都是c.NotebookApp.ip='*',我照着测试后踩了不少坑。测试

物理机打开浏览器
输入
http://192.168.xxx.xxx:8888/code

输入前面设置的密码。ip