Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

what is the max permissible length of password on unix/linux system?

share|improve this question
If the answer isn't 42, it should be. –  tvanfosson Jun 4 '10 at 21:55
a better question might be: what can I reasonably expect someone to type? If the limit is 40 and you are exceeding that, you are doing something wrong. –  msw Jun 4 '10 at 23:40
add comment

migrated from stackoverflow.com Jun 4 '10 at 21:59

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 16 down vote accepted

If your system uses a cryptographic hash to store passwords i.e. MD5, SHA1, etc then there is no limit to the password length itself since these hashes can be created with any amount of data. An MD5 or SHA1 hash can be created for an entire hard drive and this is commonly done for forensic purposes because if even one bit is changed ever so slightly then you have a very different hash and hence you can verify the data has changed. This means you can use these exact same algorithms to test if data has been tampered with. Linux (current Linux at least) uses these same hash functions. It will ask you for a password and it will then create a cryptographic hash of the password you gave and see if this hash matches the stored password. This also means that your passwords are not stored in plain text and the only way to recover a lost password is to run a brute force test which generates password hash after password hash until a it finds one which matches the current hash and then you have your password.

There is a slight downside to using these hashes which is that a hash has a finite size for example an MD5 hash is 128 bit. This means that an MD5 hash only has 2^128 or 340,282,366,920,938,463,463,374,607,431,768,211,456 possible combinations. Now while that is a big number, what this means is that you can have what they call a hash collision where you have two different items or keys that produce the same hash. In theory, the larger the key size, the lower probability of a collision and the longer it should take to brute force a password but that is strictly evaluating the entropy and how long it CAN take but there is also a chance that the first entry they try can be the one which matches even if it's a hash collision. Generally speaking, you really are safer using a hash which has a larger key size because, suppose this is MD5, the odds of the first password matching out of 340,282,366,920,938,463,463,374,607,431,768,211,456 possible matches is extremely extremely unlikely. Also pick a good password because a lot of crackers will try and use word lists, name lists, and mutations of these list (i.e. if the word is "fish" then they will try fish1234, fish!@#$ etc) before they rely on brute forcing a password.

The way you can tell if your system uses cryptographic hashes to store passwords is take a look at the /etc/shadow file (assuming you have root access). Every line is formatted like user:password:last-changed:minimum-age:maximum-age:warning-period:inactivity-period:expiration-date:reserved. The password field may start with $num$ (i.e. an md5 hash in the password field looks like $1$01234567$b5lh2mHyD2PdJjFfALlEz1 where it starts with $1$). If it starts with this, then that means your system is using a cryptographic hash. The format of the password field on all modern systems is $id$salt$hash. The id specifies what type of cryptographic hash you are using. The salt is a randomly generated string that is concatenated with the key (plain text password) in order to protect against precomputed tables of known hashes. The hash is the cryptographic hash created from the salt and key/password. If your password field starts with $num$ then you are using cryptographic hashes.

So you know, the numbers mean this:

  • $1$ means you are using MD5
  • $2$ or $2a$ means you are using blowfish
  • $5$ means you are using SHA-256
  • $6$ means you are using SHA-512

SHA-512 is the best available hash to use that glibc offers. I don't know how strong blowfish is but it is not part of glibc and therefor is only available on certain distributions that have added it. SHA-512 produces 512 bit keys or 2^512 possible combinations before a collision can be expected and with a complex enough password, it would take a cluster of computers a very very long time to find either the actual password or a collision in the hash.

Also, if you have a hash which does not start with $num$ then you are using DES and that is limited to 8 character length. I believe older system that use DES, or at least some of them, they will take any size password but only use the first 8 character. This means if you set your password to mybigbigapple and someone uses the password mybigbigcity then they will be allowed in because DES will only use mybigbig and anything after that is discarded.

So you know, Ubuntu as of 8.04, which was released in April 2008, used MD5 hashes. Ubuntu from 8.10, which was released in October 2008, and all versions since then use SHA-512 hashes. I don't know how far before April 2008 but I believe for several years if not more, most all distributions used hashes.

Now the length the key or password allowed for any hashing algorithm isn't the only thing to determine what size password you are allowed to have. The other item of interest is how the program is written and what length program itself will support. All modern passwd programs and probably most the crypt(3) function in Linux. crypt for a long long (since at least MD5 was used and probably before that) has allowed character pointers for the actual key. This means that the only limit on how long of a key it will accept is based on how much RAM that program has available to it but in all likelyhood, this is probably far far far longer then any password any person would ever be able to remember (millions of characters?).

This should answer your question as to how long a password can be. Hope I helped.


share|improve this answer
+1 for a fantastic answer. –  Sathya Oct 22 '10 at 20:56
"What is the max length of a SU answer?" lol Great answer! –  KronoS Oct 22 '10 at 20:57
add comment

It depends on which authentication module is used. In modern Linux systems, there is no maximum limit on password length. Some obsolete systems might have limits imposed by their password storage system -- popular maximums seem to be 8, 40, and 255.

share|improve this answer
add comment

Depending on how the password is stored, MD5, SHA1, BlowFish etc I think there is no limit on password set by the storage method itself.

Older implementations might have a limit that is probably 8 or 255 characters.

This does seem like a question better suited for www.serverfault.com though :)

share|improve this answer
This is general computer related, not necessarily specific to servers though! –  Darth Android Jun 4 '10 at 23:19
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.