Can't get into headless pi, password not 'raspberry'
Jan 25, 2025 Last reply: 1 year ago 21 Replies
C
Chris Green
I am trying to set up a new, headless Pi 4B. I have copied the 'lite' image to a USB drive and created the empty 'ssh' file in the boot partition.
It boots OK and the ssh deamon is running but the default username 'pi' and password 'raspberry' don't work. How on earth do I get into it to start it up?
I can edit files on the USB drive OK so I can add and modify entries in /etc/passwd and /etc/shadow. So all I actually need to do is set it up so the user 'pi' has no password but I'm not doing too well at doing that at the moment.
Any ideas, or other ways to get into it?
Didn't find your answer? Ask the community — no account required.
C
Chris Townley
There is no longer a default user in current images. When you sue the Raspberry Pi Imager, you must use the option to set a user and password, and if needed to enable ssh
P
Pancho
Use the Raspberry Pi Imager, it is good. That allows you to do some boot provisioning, this is a more up to date version of the ssh file in boot. I think there is a .yml provisioning file, but I get confused between different OSes.
The other way is to use a .ssh/authorized_keys file, with an appropriate key set up on the machine you are coming from.
B
bp
Chris Green snipped-for-privacy@isbd.net wrote: [regarding getting into a pi]
Since nobody else brought it up, a serial console is useful in this context and also as a maintenance tool.
hth,
bob prohaska
L
Lawrence D'Oliveiro
Try putting this in the password field in the /etc/shadow file:
. The various hash algorithms that should be available are documented here
formatting link
.
B
Bob Latham
Question if I may? How do you get to the /etc/shadow file if you can't log in to the pi?
Probably a couple of years ago now I created my own userconf file which along with an empty SSH file I drop into a newly burnt SD card. This works just fine for me but I would love to know how get to anything on the other partition without logging in. I am unaware of any way to see the main partition when the SD card is plugged into a PC.
Thanks.
Bob.
T
The Natural Philosopher
Others have told you how to use the imager, but IIRC all that does is set up a file in the VFAT partition....
Here is a shameless cut'n paste
Write the Raspberry Pi OS image to your SD card as normal Mount the newly written /boot partition on the Pi on your computer Create an empty file named ssh, without a file type / ending. On Linux and macOS, this is easily done with touch ssh if you’re in the right directory. This tells the OS to enable SSH access right away. Next, create a user with a password on the SD card as that’s not done automatically anymore. Create an encrypted password for your new Raspberry Pi user. On Linux and macOS, this can be done with OpenSSL. For added security, write the new password into a masked shell variable so it doesn’t show up in your computer’s shell history:
the long random string is your encrypted password. Next, create another file next to the ssh file on the SD card’s boot partition named userconf.txt. Open userconf.txt with your favourite text editor and in the first and only line enter your desired username and the encrypted password, separated by a colon. It should look like this: morph:$6$4E2z6hQOGLZCK5ZN$ESo2r/tO7Sy1Xmyp/bFzQ0A8zNNMhOoj0XocoGVbc8PVLcHlDr/kQiRvv/vOfdopLkylTVQSfK4n97SR9VGGF1
And that’s it. Unmount your card, pop it into the Pi, connect it to your network and boot. You should now be able to SSH into it using your new credentials. No monitor needed.
C
Chris Green
Ah, that would explain it, thanks. I just used dd to create the image, I'll have to add a user and so on. OK, no problem.
C
Chris Green
Yes, .ssh/authorized_keys would seem to be the way to go, thanks.
C
Chris Green
By editing it in the file system that appears when you plug the USB stick into a PC, easy! :-)
Both partitions appear when I plug it into my Linux boxes, e.g. when this particular USB is plugged in I see:-
Last time I used it, it would let you enter "root" for the username, but it wouldn't set the password for root.
T
The Natural Philosopher
I didn't find it so.
Essentially you need to create a file userconf.txt with one line
user:<encrypted password>
in the root of the VFAT boot partition
And if you have a linux system already, you can cut and paste it out of your own /etc/shadow
Plus an empty file called ssh. Using 'touch ssh'
Hardly rocket science
T
The Natural Philosopher
I believe that is the case.
It is actually quite handy to have a spare keyboard and HDMI monitor when bringing up headless.
And suitable adapters.
But its not actually needed
C
Chris Green
Oops, just rebuilt it and they are:-
/media/chris/bootfs/ /media/chris/rootfs/
C
Chris Green
True, I'm trying it now as my rpi-imager experience isn't being very fruitful at the moment.
B
Bob Latham
Erm, not here!
My PC can read and write the FAT32 bootFS which is how I can add both SSH and userconf files. But the other partition, ext4 rootfs is invisible on my PC.
Oh, So you mean a Linux PC, that I can believe but I don't know anyone who has such a beast, I've not even seen one. Apple-mac or Windows without exception in my acquaintances and all would think a 'PC' meant windows.
Before anyone makes the obvious claim, in my eyes a pi doesn't qualify as a PC.
Bob.
T
The Natural Philosopher
Ah. Yes. From Windows only the VFAT boot partition is (normally) visible. But thats where you plonk userconf.txt so it should all work OK.
Generating the password may not be so easy - not sure what tools windows has for that.
I wonder if a blank password would work?
C
Chris Townley
Correct, they specifically stopped that
M
Mike Powell
This is some of the reason I have been drawn to sbc computing over the past few years. Adding things to them is not quite like the old "open the case and slide a new card in" procedure, but the ability to tinker is still certainly there.
SLMR 2.1a * If you chose not to decide, you still have made a choice!
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.