Ubuntu – How to change the shadow file manually

shadow

I have a linux system and I create 20 users, after that I made a hash and import that into the shadow file instead of one of them(manually). I do that because of some educational things 🙂

user12:.rAuPMqtz7dZzHdfQMLJzum6vPYKJynmE29reN27MG/AsAHHt6a.1ZeyEkoo6xEJIzepKMyLai/:16607:0:99999:7:::

Then I saved the shadow and tested the user. It doesn't work. Why?
But it works when I used passwd user12.

Another problem is when I change the shadow manually (even one space or enter key) all of the users that I had can't connect via ssh. They see permission denied. Why?

I copy-pasted the content of shadow and it doesn't work again. Why? Before I copied, it works. Just opening and saving it causes it to not work?

Best Answer

This doesn't have a valid password hash:

user12:.rAuPMqtz7dZzHdfQMLJzum6vPYKJynmE29reN27MG/AsAHHt6a.1ZeyEkoo6xEJIzepKMyLai/:16607:0:99999:7:::

On Linux, the password-hashing algorithms are DES, MD5, SHA-256 and SHA-512 (see man 3 crypt, not counting Blowfish), and the length of the password hash you have given doesn't match the lengths output by any of these (13, 22, 43 and 86 characters respectively, where yours is 75 characters long). and further, it doesn't have a salt or algorithm identifier. The system will try to read it as a DES-hashed value, with the first two characters being the salt - but who knows what password will match it then?

Related Question