How To Change/Override Linux Password from other Linux PC

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 /etc, /dev, /proc, and others.

2. Information of user and passwords in most linux systems are kept in a text file, consecutively /etc/passwd and /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

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 shadow.