Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Keycatowo/f9d69eb1b2145f21cff7c9d19cc32810 to your computer and use it in GitHub Desktop.
Save Keycatowo/f9d69eb1b2145f21cff7c9d19cc32810 to your computer and use it in GitHub Desktop.

利用ssh在本機連接到Server端執行jupyter notebook來撰寫python程式

tags: Linux,Jupyter,python

背景說明

現在因為各種人工智慧的發展趨勢所以Python也成為了許多人剛入門寫程式的主要語言,而很多學校的實驗室都有架自己的Server。 平常可能都是用自己的筆電在寫code,那如果只是跑一些小東西可能還好,但如果要訓練比較大型的程式的時候可能會讓你等的非常崩潰。

那有沒有想過,==也許可以在Server上運行Jupyter來寫Python呢?==

環境需求

  • 本文所指稱的Server皆為Linux OS。
  • 在Server上已經有安裝ssh和jupyter

完整設定流程

Server端

設定Jupyter密碼

兩次輸入密碼記得要一樣

jupyter notebook password

產生config設定檔

jupyter notebook --generate-config

開啟jupyter nobteook並設定遠端port

jupyter notebook --no-browser --port=8889
  • 如果是要用jupyter lab的話也可以,前面的notebook改成lab就好了
  • port可以換成其他自己喜歡的就好

本地端

建立本地與遠端之間的連線

ssh -L localhost:8889:localhost:8889 $username@$server_IP
  • $username換成你登入Server的用戶名
  • $server_IP換成你Server的IP地址

輸入完之後它除了建立連結以外,還會自動進入Server的bash,如果不想要進到這個地方的話可以將-L換成-NL就好嘍

開啟瀏覽器,輸入網址localhost:8889

輸入剛剛設定好的密碼

完成~

來個meme慶祝一下

同場加映:如何在iPad上連線到Jupyter?

下載Termius

建立New Host

從Port Forwarding建立連線資料並執行

用分屏模式開啟瀏覽器輸入網址

完成~

提醒事項

因為免費版的Termius不允許背景執行,所以如果要保持連線的話記得要保持它在頁面中

參考資料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment