Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am currently logged in on my Linux system and i want to output my Linux password and username on my terminal, what commands i need to write and in which file it is stored and how i can retrieve it ?

share|improve this question

marked as duplicate by Mitch, belacqua, Basharat Sialvi, Radu Rădeanu, aquaherd Jun 9 '13 at 12:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Why do you need to do this? – jackweirdy Jun 8 '13 at 16:03

In short: you can't find out what your password is.

Although it's stored in the file /etc/shadow, it's stored in a "protected" format called a hash. It's like a baked cake is to a set of ingredients, there's no way to get the flour back out of the cake.

share|improve this answer
+1 for the cake analogy. – James May 2 '14 at 16:51

The passwords are not stored anywhere on the system at all. What is stored in /etc/shadow are so called hashes of the passwords.

A hash of some text is created by performing a so called one way function on the text (password), thus creating a string to check against. By design it is "impossible" (computationally infeasible) to reverse that process.

What can be done is to try a "brute force" attack - by hashing a lot of possible passwords until the outcome equals the found hash. There is no other way, you cannot compute a text (=password) that matches the hash you have.

There are several algorithms to create hashes, they differ in complexity, length of the hash, probability/possibility of so called collisions (two different texts have the same hash, which eventually must happen if the hash is shorter than the original text).

Typical current algorithms are

  • MD5
  • SHA-1 (also called SHA)

both should not be used for cryptographic/security purposes any more!!

  • SHA-256
  • SHA-512
  • SHA-3 (KECCAK was announced the winner in the competition for a new federal approved hash algorithm in October 2012) - not used in Ubuntu yet.
share|improve this answer

As you know from other answers you can't see your password. Let me explain why. Design where passwords are stored in their normal form (it's called plain) isn't very secure (not only for operating systems) because if list of such passwords falls into hands of malicious person, he can log in instantly, since list of user names is usually easy to retrieve (in Linux from /etc/passwd file). That's why hash functions are used instead. These are one-way functions - you can create hash based on value but you can't create value based on hash. If malicious person gets a list of hash values he can't retrieve actual passwords from them (or at least it's more difficult) and user still can login - when he passes his password, it's translated to hash and compared with stored value.

Once in a while you can heard that someone hacked some website and get passwords or that some list of passwords leaked somewhere. If those were stored in plain text, attacker got instant access to some accounts. If those were hashed he had to break them first. It means more trouble for him and more time for reaction like changing a password to a new one. Linux (and any Unix based system) follows this design and that's why you can't print your password in any other way that hashed - only if you have root user privileges and can read /etc/shadow file.

To print your username, type whoami.

share|improve this answer

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