How to reset Raspbian forgotten password if you still have SSH login

There’s bunch of instruction talking about how to reset password on raspbian. But they all require physical access to the raspberry pi and take out the SD card and need keyboard and monitor the reset the password.

My case is I forgot my password of course. There’s many reasons: The system is seldomly used. Forgot to put the password into password manager app. The login credential is remembered in SSH client. However, because the credential is kept in SSH client which means I can still log into the raspbian, only thing is I don’t know the password now, and no way to change it.

I tried all possible ‘dictionary attack’ to my pi but no success. Then at the last resort, I figured out something works.

Raspbian has a default user ‘pi’ which has root access. So that I just use sudo command to view and modify the secret file /etc/shadow.

What I did is,

sudo cp /etc/shadow /etc/shadow.bak

sudo vi /etc/shadow

Remove the hashed passphrase in user ‘pi’ line.


Then Esc : wq!  force save the file

sudo passwd pi

Now it allows you to set a new password without knowing the current password. You can clean up and remove the backup shadow file if this works.

Leave a Reply

Your email address will not be published. Required fields are marked *