+ Reply to Thread
Results 1 to 2 of 2

Thread: Linux : change the root password from a bash script

  1. #1
    Junior Member
    Join Date
    Jun 2012

    Linux : change the root password from a bash script

    Okay , i`d like to change my root password using a bash script , can you tell me how can i achieve that ?

  2. #2
    The password hash is located in : /etc/shadow , you can replace that hash with a new generated one.

    You can use different hashing methods like MD5 , Blowfish , SHA-256 or SHA-512

    Password hash looks like that :
    Where $5$ means that it is encrypted with SHA-256 Hash , the middle part is the salt and the rest is the actual hash.

    You can generate a Hash using minimal C program :
    #include <stdio.h>
    #include <crypt.h>
    int main(int argc, char *argv[]) {
            printf("%s\n", crypt(argv[1], argv[2]));
    Compile with cc mkpass.c -o mkpass -lcrypt and then run with the plaintext password and salt string to generate a string you can put into /etc/shadow:

    ./mkpass yourpassword yoursalt # DES (default)
    ./mkpass yourpassword '$6$yoursalt$encrypted' # SHA-512 (quote your $)

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts