The Raspberry Pi official system cancels the pi user, how to initialize the default user and make an SSH connection without a display?

The header picture must not be missing

In the past, the official Raspberry Pi system had a default user piwith an initial password of raspberry; however, due to some security reasons, after April 2022, the default piuser of the system will be cancelled:
cancel pi user
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 bootnew SSHfile in the partition, but how to create a user?
it's actually really easy.

Flash system

First, we flash the system as before:

insert image description here
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:
Please add a picture description
flash successfully:
Successfully flashed

open ssh

The method of opening SSH is the same as before, mount the SD card we just flashed:
mount SD card
Linux and macOS can use Terminal and switch the working directory to it:
switch working directory
After that, we use touchthe command to create a file called SSH (without the file extension) :
Create a file called SSH

Windows users can directly create a new txt notepad and delete .txtthe 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)

new effect

final effect

The final effect is that you can connect to the Raspberry Pi with SSH:
SSH connection to Raspberry Pi
However, because the Raspberry Pi has canceled the default piuser, it is impossible to log in with the piuser and password: we need to create a new default user.raspberry
can not log in

Create a new default user

Now, we unplug the SD card, reinsert it into the computer, mount bootthe partition, and use Terminal to switch the working directory to it for the convenience of creating users later :
switch working directory

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

passwordReplace 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:
Call the password generated by OpenSSL on macOS
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 passwdchange it.

create user

After that, we create a userconffile called , and edit:
create 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/

create user
Here we created a mintimateuser 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:
Remote login succeeded
of course, the default is bash, I usually like to use zsh and configure oh-my-zsh:
Configured oh-my-zsh

Guess you like

Origin blog.csdn.net/weixin_43890033/article/details/125827887