I want to reset my login password on Ubuntu Server on Raspberry Pi

Asked 1 years ago, Updated 1 years ago, 384 views

I am using Ubuntu Server on Raspberry Pi4, but I lost my login password.
I think I also enabled root, but I don't even know the root password.

How do I reset my password?

If it's x64, I can boot the shell at GRUB or systemd-boot, but what should I do with Raspberry Pi?

There is no disk encryption.

Also, the GUI is not installed.

ubuntu raspberry-pi

2022-11-05 19:29

2 Answers

This is not the method I actually tried, but after a little research, it seems that there are the following methods:

Method 1

There is a way to mount an SD card with RasPi installed on a different Linux and remove the affected user's password from /etc/shadow.
(You may not be able to use this method from Windows.)

How do I reset the last password of a Pi 4 running Ubuntu server?

/etc/shadow is separated by : and the second column is the password.

"/etc/shadow" file

Method 2

You can boot to single user mode by mounting the SD card on another machine and editing cmdline.txt directly under the SD card, so you can reset (reset) the password in this state.

If the reset succeeds, remember to undo the contents of cmdline.txt and switch to normal boot.

Talk about forgetting your login password in Ubuntu on PaspberryPi3

To edit, add the following code to the end:End of line or end of line?

rw init=/bin/sh

(omitted)

Insert the microSD card into the raspie and boot.
The log will flow for a while, but when the log stops flowing, you will be prompted to enter the command by pressing Enter.
The su command can now be root.
Then change the root password with the passwd command.


2022-11-05 19:29

(Another way)
How to edit passwd files
… It should be easier than changing the shadow password
(I've never tried it)

Step


in the mounting position if auto-mounting occurs If not, you may want to follow the steps below (mnt/).

$cat/proc/partitions
...
   715 276 loop15
   716 60408 loop16
   816 31166976 sdb
   817 218750 sdb1
   81830916975sdb2

# (Check for automatic mounting)
$ mount | grepsdb

$ mkdirmnt
$ sudo mount/dev/sdb2mnt
$ cdmnt
$ lessetc/passwd
root: x:0:0::/ root:/bin/bash
bin:x:1:1:/:/usr/bin/nologin
daemon: x:2:2::/:/usr/bin/nologin
mail:x:8:12::/var/spool/mail:/usr/bin/nologin
ftp: x:14:11::/srv/ftp:/usr/bin/nologin
http:x:33:33::/srv/http:/usr/bin/nologin
...
USER:x:1000:1000:COMMENT:/home/USER:/bin/bash

The UID of the registered user should be 1000
The second item, 'x', means using a shadow password, and if you delete this character, you will have no password.
(Be careful not to edit /etc/passwd by mistake.)

Edit should be available at least vim.tiny or nano
Post-Edit Processing

$sync
$ cd..
$ sudo umount mnt
$ rmdirmnt

Also, it would be good to start with this microSD and set a new password

Note: passwd


2022-11-05 19:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.