# 前置作業 ###### tags: `TensorFlow` ## 一、Ubuntu SSH與防火牆設定 ```bash= # 更新apt套件資訊 sudo apt-get update sudo apt-get upgrade # 安裝net-tools 才可使用ifconfig sudo apt install net-tools # 安裝ssh sudo apt-get install -y openssh-server # 查看ssh狀態 sudo systemctl status ssh.service # 設定常駐ssh sudo systemctl enable ssh.service # 打開防火牆port8888 讓jupyter notebook或jupyter lab可以連進來 sudo ufw allow 8888 # 重啟防火牆生效設定 sudo systemctl restart ufw ``` ## 二、Jupyter Notebook安裝及設定 ```bash= # 安裝jupyter notebook sudo apt-get install jupyter # 建立jupyter notebook設定檔案 jupyter notebook --generate-config # 修改jupyter notebook配置 sudo nano /home/[username]/.jupyter/jupyter_notebook_config.py # 路徑的username要換成自己的 # 將設定檔案內的c.NotebookApp.ip由localhost改為對外開放 c.NotebookApp.ip = '0.0.0.0' # 儲存後即可由windows連線 # 將設定檔案內的token和密碼要求拿掉 c.NotebookApp.token = '' c.NotebookApp.password = '' # 儲存後即可不用token和密碼即可直接連線jupyter notebook # 啟用jupyter notebook jupyter notebook ``` ## 三、Jupyter Lab安裝及設定 ```bash= # 安裝jupyter lab sudo pip3 install jupyterlab # 記得加sudo # 產生jupyter lab設定檔案 jupyter-lab --generate-config # 不要加sudo 若加sudo會將config存到root底下 # 修改jupyter lab配置 sudo nano /home/[username]/.jupyter/jupyter_lab_config.py # 路徑的username要換成自己的 # 將設定檔案內的c.NotebookApp.ip由localhost改為對外開放 c.ServerApp.ip = '0.0.0.0' # 儲存後即可由windows連線 # 將設定檔案內的token和密碼要求拿掉 c.ServerApp.token = '' c.ServerApp.password = '' # 儲存後即可不用token和密碼即可直接連線jupyter notebook # 啟用jupyter lab jupyter lab ``` ## 四、將Jupyter Lab及Notebook在開機中常駐 ```bash= # 先進到/etc/systemd/system 資料夾中 cd etc/systemd/system # 新增一個jupyter-lab.service 檔案 sudo nano jupyter-lab.service sudo nano jupyter.service # notebook # 將下列程式碼貼入檔案中 [Unit] After=network.service [Service] ExecStart=jupyter-lab # 若是notebook,就改成jupyter notebook User=<username> # 輸入自己的username [Install] WantedBy=default.target # 設定常駐jupyter lab (notebook) sudo systemctl enable jupyter-lab.service sudo systemctl enable jupyter.service # notebook # 開啟jupyter lab (notebook) 在背景執行 sudo systemctl start jupyter-lab.service sudo systemctl start jupyter.service # notebook # 查看jupyter lab (notebook) 使用狀態 sudo systemctl status jupyter-lab.service sudo systemctl status jupyter.service # notebook ``` 若有成功就會出現下列畫面 ![](https://i.imgur.com/XXWt9p0.png) 這樣下次開機後不用再用虛擬機開啟jupter lab後才能用本機端去連線! ### 參考文章 彥廷筆記 https://hackmd.io/@suyenting/SyzKlwxmO