LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   migrating /etc/passwd (and shadow) between machines: why should it work? (https://www.linuxquestions.org/questions/linux-newbie-8/migrating-etc-passwd-and-shadow-between-machines-why-should-it-work-726052/)

genmaicha 05-14-2009 03:11 PM

migrating /etc/passwd (and shadow) between machines: why should it work?
 
So apparently it's possible to copy entries from the /etc/passwd and /etc/shadow from one machine to another, and it 'just works'. My question is, why? According to the shadow(5) manpage, the passwords are encrypted via the crypto function which takes a salt. Do all distros use the same salt? Otherwise I don't see how this is possible.

forrestt 05-14-2009 03:20 PM

The salt is part of the shadow entry. The entry is broken down as:

Code:

struct spwd {
        char          *sp_namp; /* user login name */
        char          *sp_pwdp; /* encrypted password */
        long int      sp_lstchg; /* last password change */
        long int      sp_min; /* days until change allowed. */
        long int      sp_max; /* days before change required */
        long int      sp_warn; /* days warning for expiration */
        long int      sp_inact; /* days before account inactive */
        long int      sp_expire; /* date when account expires */
        unsigned long int  sp_flag; /* reserved for future use */
}

The sp_pwdp portion is a $ separated value string with the portions between $'s being:

single_digit signifying the method of encryption
salt
encrypted password

HTH

Forrest

genmaicha 05-14-2009 03:36 PM

awesome, I can reproduce the hash in my /etc/shadow by using the salt "$1$abcdefgh" for crypt(). What other encryption methods are there besides md5 and des? my man crypt doesn't mention anything else.

forrestt 05-14-2009 03:43 PM

Here is what my man says about it:

Code:

NOTES
  Glibc Notes
      The glibc2 version of this function supports additional encryption algorithms.

      If salt is a character string starting with the characters "$id$" followed by a string terminated by "$":

              $id$salt$encrypted

      then instead of using the DES machine, id identifies the encryption method used and this then determines how the rest of the password string is interpreted.  The following values of id are supported:

              ID  | Method
              ---------------------------------------------------------
              1  | MD5
              2a  | Blowfish (not in mainline glibc; added in some
                  | Linux distributions)
              5  | SHA-256 (since glibc 2.7)
              6  | SHA-512 (since glibc 2.7)

      So $5$salt$encrypted is an SHA-256 encoded password and $6$salt$encrypted is an SHA-512 encoded one.

      "salt" stands for the up to 16 characters following "$id$" in the salt.  The encrypted part of the password string is the actual computed password.  The size of this string is fixed:

      MD5    | 22 characters
      SHA-256 | 43 characters
      SHA-512 | 86 characters

      The characters in "salt" and "encrypted" are drawn from the set [a–zA–Z0–9./].  In the SHA implementation the entire key is significant (instead of only the first 8 bytes in MD5).

HTH

Forrest

p.s. So, I guess the ID isn't limited to one char I've just only ever seen one.


All times are GMT -5. The time now is 10:03 AM.