樹莓派是自帶有無線網卡的,所以可以連接 wifi。
本文的樹莓派系統環境是 Ubuntu Server 20.04,其他 Linux 系統都大同小異。
ssh 進入樹莓派。
1.第一步設置時區
sudo tzselect
# 選擇4 Aisa
# 然后選擇9 China
# 接着選擇1 Beijing Time
# 最后選擇1 確認
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
設置完成后執行 date -R 看時間是否准確。
2.設置 wifi
cd /etc/netplan/
sudo vim 50-cloud-init.yaml
打開后應該會有以下內容:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
version: 2
現在需要加一個wifi的配置,示例如下:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
dhcp4: true
access-points:
<wifi名字>:
password: "<wifi密碼>"
version: 2
編輯完成后保存,然后執行命令
sudo netplan --debug apply
3.檢查設置
執行命令 ifconfig 檢查是否有網卡 wlan0 的信息,並且獲取到了ip,最后通過這個ip進行 ssh 連接,如果連接成功,那就沒有問題了。

