Try   HackMD

如何在沒有螢幕或鍵盤的情況下設置Raspberry Pi

  • 有 一種方法可以設置和處理樹莓派,而無需將其連接到螢幕或鍵盤。它被稱為無頭(headless)運行樹莓派。
  • 本文使用 Raspberry Pi 3 B+ 進行初始設定
  • 使用Raspbian with desktop
    • Version:February 2020
    • Release date:2020-02-13
    • Kernel version:4.19

需要配備

  • 一台可上網的電腦
  • SD card讀卡機
  • 乙太網路線
  • ' 當前使用的網路路由器

需要軟體

  • 樹莓派作業系統 Raspbian
  • Win32 Disk Imager
    • 用於將映像檔寫入隨身碟或SD / CF卡的Windows工具
  • PuTTY
    • 遠端 SSH 連線工具
  • Advanced IP Scanner
    • 找到您的Raspberry Pi的本地IP地址

設置步驟

  1. 任何大於32GB的SD卡都是SDXC卡,為exFAT文件系統。樹莓派僅支援FAT32,需要先將其重新格式化。
  2. 用Win32 Disk Imager將Raspbian 映像寫入SD卡
  3. 映像寫入完成後,創建一個名為“SSH”的空文件,並將其放在SD卡的根分區中。
  4. SD卡插入樹莓派。
  5. 使用乙太網路線將樹莓派連接到您的網路路由器,然後插入電源線使樹莓派啟動。
  6. 打開Advanced IP Scanner,掃描找出樹莓派的IP。
  7. 打開PuTTY,在“Host name”輸入框中輸入樹莓派連本地IP地址,並點擊“Open”以啟動連接。
  8. 在第一次連接嘗試時,將出現安全性警告。只需按“是”,因為您要連接到自己的樹莓派。
  9. 出現登入畫面。如果這是您第一次登錄而且尚未更改用戶名或密碼,請輸入pi作為用戶名,輸入raspberry作為密碼。
  10. 輸入sudo raspi-config進入設置菜單來配置樹莓派

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

初始wifi設定

  1. 輸入sudo raspi-config進入設置菜單
  2. Network Options > Wi-fi
  3. 選擇 Wi-fi country

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. 輸入SSID及passphrase

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

本地化設定

  1. 輸入sudo raspi-config進入設置菜單
  2. Localisation Options

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. Localisation Options > Change Locale
  • en_US.UTF-8 (default)
  • zh_TW.UTF-8

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. Localisation Options > Change Timezone > Asia > Taipei

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

介面設定

  1. 輸入sudo raspi-config進入設置菜單
  2. Interfacing Options
  3. 開啟 SSH, VNC, 其餘看需求設定

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

手動增加wifi

step1:
使用文本編輯器編輯wpa_supplicant.conf
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

wpa_supplicant.conf :

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=TW

network={
        ssid="YOUR WIFI NETWORK NAME"
        psk="YOUR WIFI PASSWORD"
        key_mgmt=WPA-PSK
        priority=1
        id_str="school"
}

若要將PSK加密,可以使用wpa_passphrase實用程序生成加密的PSK。

wpa_passphrase "testing" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null

程序會直接提供輸入行,請輸入密碼後按Enter。

輸入的密碼會輸出到屏幕,請注意。

程序加密完密碼後,會將配置內容附加wpa_supplicant.conf

最後在使用文本編輯器編輯wpa_supplicant.conf

step2:

  • 啟用dhcpcd服務(開機啟動)
    sudo systemctl enable dhcpcd

  • 手動啟動dhcpcd服務
    sudo systemctl start dhcpcd

  • 重新啟動dhcpcd服務
    sudo systemctl restart dhcpcd

ifconfig wlan0
inet addr字段旁邊有一個IP位址,表明Raspberry Pi已連接到網絡。

更改使用者(pi)密碼

  1. 輸入sudo raspi-config進入設置菜單
  2. Change User Password

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. 輸入新的密碼及確認密碼,成功修改後重開機sudo reboot

遠端桌面

  1. 輸入sudo raspi-config進入設置菜單
  2. Interfacing Options > VNC > enable
  3. 重開機sudo reboot

遠端桌面操控

預設(RealVNC)

  1. 讓樹莓派使用區域網路的WiFi連線
  2. 打開Advanced IP Scanner,掃描找出樹莓派的IP
  3. 本地電腦 下載 VNC Viewer並開啓VNC Viewer
  4. 選擇 File > New connection,開始設置Properties
  5. 在General頁籤
    • VNC Server = 樹莓派IP
    • Name = 自訂名稱
  6. 在Options頁籤
    • 取消勾選view-only
    • Scaling選Automatic,勾選Preserve aspect ratio
  7. 創建完成後,啟動connection,並輸入帳號密碼即可遠端桌面操控

中文輸入法

  1. 更新套件資料庫 sudo apt update
  2. 安裝SCIM新酷音輸入法 sudo apt-get install scim-chewing
  3. 重開機sudo reboot
  4. 選擇SCIM

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. 介面(前端) > 全域設定 > 下一種輸入法 > 設定左邊shift為切換語言鍵

  1. 輸入法引擎 > 全域設定 > 設定所需的中文輸入法

  1. 重開機sudo reboot

參考