天天看點

通過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需要),打開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 localhost:8888:localhost:8888 remote_user@remote_host      

其中: -N 告訴SSH沒有指令要被遠端執行; -f 告訴SSH在背景執行; -L 是指定port forwarding的配置,遠端端口是8889,本地的端口号的8888。remote_user@remote_host 用實際的遠端帳戶和遠端位址替換

ssh -N -f -L localhost:8888:localhost:8888 [email protected]      

(6)本地機器的遠端連接配接界面MobaXterm(Terminal)中啟動Jupter notebook

jupyter notebook      
通過SSH遠端使用jupyter notebook

參考文獻:

  1. ​​Jupyter notebook遠端通路伺服器​​
  2. ​​通過SSH遠端使用jupyter notebook​​

作者:​​楚千羽​​