title: How to encrypt passwords stored in a file rather than /etc/shadow in Linux
body: <p>I want to create a new file called <code>/home/secret.txt</code> with the usernames and passwords stored, similar to <code>/etc/shadow</code> format in Linux. All new users are placed into this new file rather than <code>/etc/shadow</code>. From my bash script I am doing as follows:</p>
  
  <pre><code>echo "user1:password::root:root:/home/user1:/bin/bash" &gt;&gt; /home/secret.txt
  echo "user1:password" | chpasswd -c MD5
  </code></pre>
  
  <p>In the 2nd statement, I am trying to change the password into encrypted but <code>chpasswd</code> fails saying <code>chpasswd: line 1: user 'user1' does not exist</code>. I think <code>chpasswd</code> changes/encrypts passwords for the users present in /etc/passwd or /etc/shadow. Because of this the password field in the file is not encrypted. </p>
  
  <p>May I know how to write username and password similar to <code>/etc/shadow</code> format into a temporary file with passwords being encrypted ?</p>