Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Shadow: How does the encrytion work?


    I hope its okay that I started another thread. I got another question about how encryption of user passwords works in linux. I really want to understand, how its done.

    Unfortunately looking at the sources of passwd and googling doesn`t get me an answer.

    I wonder why SHA-512 (an I think the other algorithms, too) are shortend as it can be at max 160 bits long. So why does passwd only saves 84 chars? Do I missing something?



  2. #2
    Linux Engineer
    Join Date
    Jan 2005
    Saint Paul, MN
    The password is encrypted with a one-way encryption (i.e. it can not be decypted). When the user enters a possible password, it is encrypted and that result is compared to the saved encrypted password within the shadow file. A long time ago, the ecrypted password was saved in the "passwd" file; however, since it could be viewed by anyone it was not secure when people started feeding dictionary of words into the encryption method and recording the clear word and the encrypted password strings in "password dictionary" where a matched encrypted password provided the clear password. The shadow file can not be viewed my anyone but root (and root does not need the proper password to switch to another user so we generally trust them to not access other accounts except for as needed).

  3. #3
    Okay, figured it in detail by looking in the sources of shadow package.

  4. $spacer_open
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    For standard Unix/Linux password encryption, they use a "salt" value, which is the first 2 bytes in the encrypted password. When you use the crypt() function, you pass those bytes to the function as the salt value, and the plaintext of the input password. It generates the encrypted version, which should compare as a string with that stored in /etc/shadow. The original salt value is created from a number of factors, such as date, time, etc. When I had to build such systems for a major manufacturing software system, we used a hash function on the password + other stuff to create the salt value that would be used to encrypt the password. It works very well, and has done so for almost 20 years now, running most of the 300mm semiconductor fabs in the world.

    Anyway, as alf55 said, this is a one-way encryption (DES-56 based) in that you cannot derive the original plaintext password from the encrypted version. Although it may be susceptible to a dictionary or brute force attack (the salt value is kept in /etc/shadow), otherwise it is quite secure provided you make sure that your users don't use totally dumb passwords that are easily guessed or derived.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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