Q. Can you explain /etc/shadow file used under Linux or UNIX?
A. /etc/shadow file stores actual password in encrypted format for user's account with additional properties related to user password i.e. it stores secure user account information. All fields are separated by a colon (:) symbol. It contains one entry per line for each user listed in /etc/passwd file Generally, shadow file entry looks as follows (click to enlarge image):
/etc/shadow file fields

(Fig.01: /etc/shadow file fields)
- User name : It is your login name
- Password: It your encrypted password. The password should be minimum 6-8 characters long including special characters/digits
- Last password change (lastchanged): Days since Jan 1, 1970 that password was last changed
- Minimum: The minimum number of days required between password changes i.e. the number of days left before the user is allowed to change his/her password
- Maximum: The maximum number of days the password is valid (after that user is forced to change his/her password)
- Warn : The number of days before password is to expire that user is warned that his/her password must be changed
- Inactive : The number of days after password expires that account is disabled
- Expire : days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying when the login may no longer be used
The last 6 fields provides password aging and account lockout features (you need to use chage command to setup password aging). According to man page of shadow - the password field must be filled. The encrypted password consists of 13 to 24 characters from the 64 character alphabet a through z, A through Z, 0 through 9, \. and /. Optionally it can start with a "$" character. This means the encrypted password was generated using another (not DES) algorithm. For example if it starts with "$1$" it means the MD5-based algorithm was used.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 06/3/08


{ 41 comments… read them below or add one }
What does a symbol of ! or * indicate when placed before this after the user login name . . . after typing cat /etc/shadow?
! or * indicate that the user will not be able to use a unix/linux password to log in. In other words user login will be disabled.
HTH
Nice to get this information here, couldn’t understand it when our teacher taught it in class
If a user changes his password (using passwd command), how is the shadow file updated to include the new passwd? I mean, doesn’t the root/admin only have write permissions to this file?
passwd command has SUID (Saved User ID) enabled. When passwd command executed the effective user id (EUID) that is in force at the time is copied to the saved user id (i.e. root). Using this technique a normal user can update his/her password.
username:!!: …. or
username:!!$1$MvGJq5Nq$ersjw/IaU90l.n5sB/FFP1: …
I tried this on Linux machine and !! appeared after passwd -l username command – locking password.
After passwd -u username – unlock, !! disappeared again.
So this means that user cannot log in, so it is blocked, but I am not sure about all those rpm, nscd, nfsnobody and so on users.. they have only :!!: in password field in ect/shadow file. These users cannot log in, but are they entirely blocked?
The root user can still access accounts with blocked passwords, using su, but only if those accounts have a shell enabled in /etc/passwd (if the shell is /sbin/nologin, even root cannot access the account). I don’t know if there’s a difference between !! and * in the password field of the shadow file, though.
Is it possible to have etc/shadow file where all the passwords are encrypted however one password is simply a recognizable word?
one password is simply a recognizable word?
Noop.
can any one make answer more clear how passwd changes the password although /etc/shadow has permissions ‘r——–’ with root as owner.
If there is an account in the etc/shadow file and the account does not have an equivalent in the etc/passwd file? Will the account work for login?
@sunil
heya mate. the passwd command can only be run by root or as a root (using sudo). The root can access (including read and write) to any file even if he doesnt have the permissions. Thats why as a root, the /etc/shadow can be changed.
You can call it perks of the job…
HTH
sunil-
passwd command can be run by any user. when root runs it, they dont need to specify an old password to change it.
Hey guys,
Can you please tell me if
1. \”!!\” means that the password is expired and the user will not be able to login?
2. \”*\” means that the userid is locked?
the passd command is both SUID and SGID — these stand for Set User ID and Set Group ID. See permissions below;
% ls -l /usr/bin/passwd
54 -r-sr-sr-x 1 root sys 27228 Aug 16 2007 /usr/bin/passwd
Just to clarify the perms –
* user perms (root) – read, setuid on execute
* group perms (sys) – read, setgid on execute
* anyone perms – read and execute
So, when anyone runs the passwd command, they will effectively be running it as the root user and the sys group.
Although the permissions of passwd are read (no write), root does have the ability to force write on any file on a UNIX system (locally mounted).
That is why when you run the passwd command, you effectively become root and the shadow file is updated.
Hope that helps.
username:Kz5iZvRZAyXkQ:14132::::90::
I use the passwd -x -1 [username] command to remove the expirations, etc., but that 90 keeps showing up. How the hell do I get rid of that damn number short of vi’ing the shadow file?
Does anyone know how to set a madatory minimum length for the root password. I typed in PASSWORD=14 in the ../etc/default/passwd file, but that only ALLOWS a 14 charachter password. It doesn’t require it.
Thanks,
David
@David,
To improve security, you need to use longer password. It can be enforced using Pluggable Authentication Module (PAM).
“/etc/shadow file stores actual password in encrypted format”
I don’t think so, I’m pretty sure that /etc/shadow stores a hashed output from the users password, by default using ‘crypt’ in solaris and therefore limited to checking the first 8 chars of a password. You can invoke MD5 or SHA-1 instead, for better password checking. /etc/default/passwd contains the hints…..
Is it possible to add an root entry to the /etc/passwd and /etc/shadow where there is no password, so that we can create a root that doesn’t have a password? thanks for the help
hi,
can one access /etc/shadow file even if one does not have root permissions…
Hey what is the mode of encryption in this shadow file?
its ok but password means nothing could be done on it……….
hi my linux friends
i m student of bannerjee sir plz help me about how to convert /etc/shadow file’s passwd into our normal form simply haching
its very easy langauage even fresher can understand explation is given briefly
Thanks a lot .. got hell lot of information
If I insert # comment lines, blank lines, or if I sort the contents differently, will this screw anything up? Will the system clobber comments, blank lines, or sort order? I could get the answer by experiment, but the risk of disaster is too high.
“if the shell is /sbin/nologin, even root cannot access the account”
False. Both su and sudo let you specify a shell/command, so you (not just root) can bypass what /etc/passwd says. The shell value there is only a default shell! It does NOT entirely prevent someone from logging in (very common myth)! In other words, if you have access to an account with su or sudo, you can log in to it regardless of what the default shell is set to. I do it all the time.
While it WOULD lock someone out of telnet, SSH2 allows you to specify an alternate shell to bypass /etc/passwd as well (although I’ve not had any success using this feature of SSH, so perhaps I’m misreading or not getting it right).
i am a student and i m new in linux ..can anyone please explain me the term dns resolver by taking into account:
1.how it might be used to resolve the url:breo.beds.ac.uk
2.how it compares with the hosts file
can anyone xplain: what happening in the boxes areas shown in the startup script of a linux system:-
checking for hardware changes [ok]
bringing up loopback interface:[ok]
bringing up loopback interface eth0:
determining ip information for etho… done
starting snmpd:[failed]
starting cups[ok]
starting sshd:[failed]
starting sendmail:[failed]
can u explain how the /etc/shadow and /etc/passwd are used in the authentication process.why are two files used instead of one?how can i convert a system to use the /etc/shadow file to store password?
an example of absolute pathname is shown as /home/student/myprogms while a relative pathname can be shown as ../../documents can anyone discuss the differences between absolute and relative pathname and advantages.
Heyy
can anyone tell me what is the hash here?
username:$1$DKzYQ$HP9PrZA.mxe5/qviB3Kyw1:14266:0:99999:7:::
i tried to crack it with md5 but it says it’s not a valid hash. I tried different combinations but it’s the same thing.
Please help.
Thanks.
Hey Kriss,
you can’t just crack md5, since md5 is actually a cryptographic hash function and it operates only ONE way: text -> hash!
You might try the common words md5 database. Type “gdata md5 database” in your favourite search engine.
If you are (un)lucky this hash will be found in the database, and you will be able to see clear text.
Could you please tell me how to open it?
Srikanth – With any text editor. However, only root has access to it.
sir mcrypt command is is nice for encryption
that’s beautiful to use.
sir how to open shadow file if permission denied?
sir how to use algorithm for encryption.
can we make algorithm ?
in unix how to use mod(%)?
@manish bagwari:
Shadow file can only be opened by a super user (already mentioned in Keilaron comment). So sudo vi /etc/shadow (and enter password, if your username is added to sudoers), or first become super user with use of the su command (must know root password), and then open the file via vi /etc/shadow.
Mod (%) in korn shell can be used in following way: mymodulus=$(( 15 % 7 ))
If you meant something else by “unix”, please let me know.
sir i have used su command ,after giving passwd it diplayed authentication failure
sir, what to do?
And how we can koow the root passwd.
Well, without correct super user password, you can NOT read requested file!
If you truly are authorised to use the system in super user mode, someone should have provided you with the password; or created rules in sudoers configuration file.
If you installed the system by your self, and just forgot the password, you will probably have to boot it using rescue CD and then reset super user password. This procedure is well documented on the web.