はじめに

研究室のiMacやLinuxサーバーの方がそりゃあスペックが良いので,普段使用しているJupyterLabをリモートからでも使用できるようにするときの設定メモです.

こちらのjupyter labをリモートから使うを参考にさせていただきました.というかほとんどこのままです.

環境

    • python3.6

 

    • Ubuntu18.04 (macOS 10.14.6でも試しました)

 

    • jupyter-notebook 6.0.2

 

    • jupyter lab 1.1.4

 

    ipython 7.9.0

手順

1.jupyterconfig.pyの作成

$ jupyter lab --generate-config
Writing default config to: /home/okuda/.jupyter/jupyter_notebook_config.py

2. ipythonでパスワードのハッシュ値を作成

$ ipython
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from IPython.lib import passwd                                                                                                                      

In [2]: passwd()                                                                                                                                            
Enter password: 
Verify password: 
Out[2]: 'sha1:xxxxxxxxx'

3. config.pyを設定

$ nano ~/.jupyter/jupyter_notebook_config.py

で,必要なところを編集.

c = get_config()
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.open_browser = False
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.port = 9999
c.NotebookApp.allow_remote_access = True
c.NotebookApp.password = 'sha1:xxxx' 

4. sshでポートフォワーディングで接続

$ ssh -p ポート番号 [user]@[ip] -NL 9999:localhost:9999

Jupyter Labを起動して,

http://localhost:9999/
にアクセスすればOKです.

Host xxx
    HostName xxx
    User xxx
    Port xxx
        IdentityFile ~/.ssh/id_rsa_xxx
    LocalForward 9999 localhost:9999

みたいなのかくと,便利!

お疲れ様です.

广告
将在 10 秒后关闭
bannerAds