Or if you have linux running on an SD card (e.g. Raspberry Pi) and you want to change the password from another your Linux PC, here’s how to do it.
1. Mount the target system on your linux PC. If it’s a Raspberry Pi SD card, simply plug it in. Now let’s say the mount point is
/media/stick, and inside that folder you will find system folder such as
/proc, and others.
2. Information of user and passwords in most linux systems are kept in a text file, consecutively
/etc/shadow. What we need to change is the latter. Open the
shadow file (use
sudo cat /etc/shadow), and see the entry for the user whom you want to change the password. The entry contains 9 fields, separated by colon (“:”). More detail on this type
man shadow on terminal. Our interest lies on the second field, which is the encrypted password field. This field has format of following:
Now look into the format of your
shadow file, if the
id is 6, most likely SHA-512 encryption is used. The other possibilities are MD5 (id 1) and SHA-256 (id 5).
3. We will use
mkpasswd, a front-end for
crypt, the function for linux password encryption. To create a new password with SHA-512 encryption, do this:
mkpasswd -m sha-512 <password> <salt>
You can pick anything for the password, but for salt you need to give 8-16 random sequence of characters. If salt is empty,
mkpasswd will generate a random salt, hence everytime you call
mkpasswd it will give different result. For
shadow, make sure you give in your salt. For example:
ariandy@linux:~$ mkpasswd -m sha-512 mypassword OhIuVG9LLE79.5XV $6$OhIuVG9LLE79.5XV$GCO6Oyd2.IeONgjXWZDXzZbU8QFDUYD2mrrhQQeRzsceGmek4SRGMqXiJbod5UQ1WivVD1GPt4k5sPo6.PVs//
Now put this output in the second field of
/etc/shadow file. Note that hashed password contains no colon, because colon is the delimiter between fields in