我的樹莓派 Raspberry Pi Zero 2W 折騰筆記,記錄一些遇到的問題和解決辦法

nauyx發表於2022-04-23

0x00 前言說明

最近買了一塊Raspberry Pi Zero 2W來玩,目的是想搭建一臺遠端執行的個人伺服器,上面放個部落格、點個燈啥的。於是就有了這篇文章。

樹莓派官網地址:https://www.raspberrypi.com/

補一張圖哈哈!

image

0x01 SSH連線

首先一開始買到手之後我是很懵的,於是在google上找到了以下幾篇文章幫助了我很多。

看了那個youtube上面的視訊後,發現其實買之前是可以叫淘寶客服幫忙焊接gpio引腳的。然後發現我身邊有一個電烙鐵,於是打算試一下(從來焊接過),結局如下

image

貼一個國外大佬的樹莓派zero2w gpio焊接教程:https://www.youtube.com/watch?v=UDdbaMk39tM&ab_channel=BasvanderSluis

還好,沒有壞掉!哈哈,這就是不看教程就直接動手的後果,望大家引以為戒!那麼,跟著上面的教程寫入作業系統到sd卡之後就是安裝驅動和ssh連線樹莓派了,連線的時候遇到了一個問題就是pi@raspberrypi.local's password,ssh登入不上去,看了下官方發現:

There are also mechanisms to preconfigure an image without using Imager. To set up a user on first boot and bypass the wizard completely, create a file called userconf or userconf.txt in the boot partition of the SD card; this is the part of the SD card which can be seen when it is mounted in a Windows or MacOS computer.

This file should contain a single line of text, consisting of username:encrypted- password – so your desired username, followed immediately by a colon, followed immediately by an encrypted representation of the password you want to use.

To generate the encrypted password, the easiest way is to use OpenSSL on a Raspberry Pi that is already running – open a terminal window and enter

echo 'mypassword' | openssl passwd -6 -stdin
This will produce what looks like a string of random characters, which is actually an encrypted version of the supplied password.

https://www.raspberrypi.com/news/raspberry-pi-bullseye-update-april-2022/

簡單來說就是樹莓派為了安全起見不在使用預設密碼,所以需要在啟動前在boot目錄下建立一個userconf.txt,格式如下:

username:encrypted-password

其中encrypted-password可以用echo 'mypassword' | openssl passwd -6 -stdin這條命令生成,貼一下我生成的配置:

pi:$6$T12E4motTbeG7HXC$0vvzm.7sNj9bsEzVL2JT4P9OYXpvsk3lwqK6CzTVyyLrRdUA.fZVWrfzqmU./mmuU1O/i3xSueXPX4ieBjrCM/

也就是使用者名稱為pi,密碼為raspberry。重新寫入sd卡之後,再次連線一波!

λ ssh pi@raspberrypi.local -p 22
Warning: Permanently added the ECDSA host key for IP address '169.254.155.237' to the list of known hosts.
pi@raspberrypi.local's password:
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Apr  4 15:41:56 2022

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.


Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

pi@raspberrypi:~ $

成功了!!!!!!!!!!!!!!!哇,成就感滿滿的!

0x02 配置網路

輸入sudo raspi-config,選擇國家—> “System Options”—>選第一個 —> 輸入WiFi名稱密碼—> 重啟sudo reboot

pi@raspberrypi:~ $ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 10  bytes 1600 (1.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10  bytes 1600 (1.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.174.149  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::74a7:e6a5:d1b2:66e  prefixlen 64  scopeid 0x20<link>
        ether 62:ae:a7:2d:b5:2f  txqueuelen 1000  (Ethernet)
        RX packets 187  bytes 19160 (18.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 5905 (5.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.4  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 240e:379:1a87:b500:fc16:62d:3ce4:de2b  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::4ee:25c1:2732:51c0  prefixlen 64  scopeid 0x20<link>
        ether e4:5f:01:4b:3a:e4  txqueuelen 1000  (Ethernet)
        RX packets 157  bytes 24008 (23.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 87  bytes 14755 (14.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

pi@raspberrypi:~ $ ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=55 time=19.8 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=55 time=23.1 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=55 time=22.9 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=55 time=22.9 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=55 time=22.8 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=55 time=24.1 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 19.849/22.594/24.104/1.306 ms
pi@raspberrypi:~ $ 

連線網路成功!哦耶!

0x03 文字結語

那麼先到這裡,後續出一個電燈的文章!!!

相關文章