In the past, the official Raspberry Pi system had a default user pi
with an initial password of raspberry
; however, due to some security reasons, after April 2022, the default pi
user of the system will be cancelled:
this is more troublesome, using the Raspberry Pi, many People do not connect to the monitor, and directly operate on the remote SSH; now, the SSH of the Raspberry Pi can still be opened by creating a boot
new SSH
file in the partition, but how to create a user?
it's actually really easy.
Flash system
First, we flash the system as before:
- For Raspberry Pi 3B and Raspberry Pi 4B, it is recommended to flash the 64-bit version system: https://downloads.raspberrypi.org/raspios_lite_arm64/images
- Generic 32-bit systems: https://downloads.raspberrypi.org/raspios_lite_armhf/images
It should be noted that the links here are all Lite versions, without a desktop environment.
If you want a desktop environment, there is probably no need to read this tutorial, and you can download it directly from the official website: https://www.raspberrypi.com/software/operating-systems/
Flash system:
flash successfully:
open ssh
The method of opening SSH is the same as before, mount the SD card we just flashed:
Linux and macOS can use Terminal and switch the working directory to it:
After that, we use touch
the command to create a file called SSH (without the file extension) :
Windows users can directly create a new txt notepad and delete
.txt
the suffix.
After that, insert the SD card into the Raspberry Pi, and you can SSH connection. Of course, if you want the Raspberry Pi to turn on Wi-Fi by default and connect...
Wi-Fi enabled by default
Open the file under the boot partition wpa_supplicant.conf
(if there is no such file, you can create it manually), add or modify it as follows:
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="WiFi-A"
psk="Mintimate"
key_mgmt=WPA-PSK
priority=1
}
network={
ssid="WiFi-B"
psk="MintimateBlog"
key_mgmt=WPA-PSK
priority=2
scan_ssid=1
}
in
- ssid: Wi-Fi name
- psk: Wi-Fi password
- priority: priority (the higher the priority, the higher the priority)
final effect
The final effect is that you can connect to the Raspberry Pi with SSH:
However, because the Raspberry Pi has canceled the default pi
user, it is impossible to log in with the pi
user and password: we need to create a new default user.raspberry
Create a new default user
Now, we unplug the SD card, reinsert it into the computer, mount boot
the partition, and use Terminal to switch the working directory to it for the convenience of creating users later :
OpenSSL encryption
This section refers to the official documentation: https://github.com/raspberrypi/documentation/blob/develop/documentation/asciidoc/computers/configuration/headless.adoc
At this time, we use the function command (actually OpenSSL) that comes with the system to generate an encrypted password:
echo 'password' | openssl passwd -6 -stdin
password
Replace it with the password you want to set.
For example, we still want to set the user to raspberry
, then use OpenSSL to encrypt the generated password:
as you can see, the generated password is$6$8WzhrUbnvxbJdS5n$p5acHHXaB02qI1eCJrSH4lSUOsXx9WnTvbNm2T9h9d/OmnFuf0qXGTAYF3GK5pqFONn7LiA4Khn4AHXcYG72D/
WIndwos currently does not have its own OpenSSL function, you can directly copy the raspberry password you set, and then log in to the server and
passwd
change it.
create user
After that, we create a userconf
file called , and edit:
use <key>:<value>
form, create user and password; where the user name is key, the password is value, and the password is the password just encrypted by OpenSSL, for example:
mintimate:$6$8WzhrUbnvxbJdS5n$p5acHHXaB02qI1eCJrSH4lSUOsXx9WnTvbNm2T9h9d/OmnFuf0qXGTAYF3GK5pqFONn7LiA4Khn4AHXcYG72D/
Here we created a mintimate
user called , and set the password to raspberry
.
Save and exit, unplug the SD card to the Raspberry Pi, and you can perform SSH remote login.
remote login
Finally, we log in remotely:
of course, the default is bash, I usually like to use zsh and configure oh-my-zsh: