通过SSH远程使用jupyter notebook

1.背景

一直苦恼于本地机器和服务器上都要配置一些机器学习方面的环境,今天花了点时间研究了下Jupter notebook远程访问服务器,所以记录一下。

有些步骤非必须,这里尽量写清楚,读者理解后自行决定如何安装,本文以非root用户安装。

2.安装步骤

(1)检查是否有安装jupyter notebook,终端输入jupyter notebook,如果报错就是没有啦,那么就用下面命令安装。

sudo pip install jupyter 

(2)生成配置文件

jupyter notebook --generate-config

(3)生成密码(后续写配置文件、登录Jupyter notebook需要),在base环境下打开python终端

In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:0e422dfccef2:84cfbcbb3ef95872fb8e23be3999c123f862d856' 

(4)修改默认配置文件

sudo gedit ~/.jupyter/jupyter_notebook_config.py 

在文件最后添加如下几行(这里可以自行配置):

c.NotebookApp.ip='*'# 此处就是星号就是对的,不用改成自己的网络IP
# c.NotebookApp.password = u'sha:ce...刚才复制的那个密文'
c.NotebookApp.password = u'sha1:0e422dfccef2:84cfbcbb3ef95872fb8e23be3999c123f862d856'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #随便指定一个端口
c.IPKernelApp.pylab = 'inline'

(5)在本地机器的远程连接界面MobaXterm(Terminal)中启动SSH

ssh -N -f -L :8889:localhost:8888 remote_user@remote_host

其中: -N 告诉SSH没有命令要被远程执行; -f 告诉SSH在后台执行; -L 是指定port forwarding的配置,远端端口是8888,本地的端口号的8889。remote_user@remote_host 用实际的远程帐户和远程地址替换

ssh -N -f -L :8889:localhost:8888 zhemglee@192.168.206.143

(6)本地机器的远程连接界面MobaXterm(Terminal)中启动Jupter notebook

jupyter notebook

image

参考文献:

  1. Jupyter notebook远程访问服务器
  2. 通过SSH远程使用jupyter notebook
posted @ 2022-10-28 22:08  楚千羽  阅读(335)  评论(0编辑  收藏  举报