Suppose I have content in /etc/shadow file like this:


and in /etc/passwd file like this:

ftp:x:40:49:FTP account:/srv/ftp:/sbin/nologin

I want to group them like:

ftp:!!:14796::::::x:40:49:FTP account:/srv/ftp:/sbin/nologin

What I did above:

I have first find the command user name from both the file and then concatenating them into single line. Also, I am deleting user name from second line (As this is already present in starting so its not needed 2 times).

What will be the simple command?


You could use the join utility

sudo bash -c 'join -t: <(sort -t: -k1,1 /etc/shadow) <(sort -t: -k1,1 /etc/passwd)'
  • Also, I only want to get users whose UID > 499 i.e. only systems users from this list. – snoop Dec 27 '14 at 14:24
  • @snoop probably the easiest way is simply to filter the output by piping it through awk e.g. if the eleventh field is the UID, then ... | awk -F: '$11 > 499' – steeldriver Dec 27 '14 at 14:48
  • Yeah, thought same thing. Awk is better for splitting and checking this condition. – snoop Dec 27 '14 at 15:35

You can use the unshadow tool in John The Ripper password decrypting tool

To do this you have to first install John to your system.

To do this go to your terminal and type the following command.

sudo apt-get install john

After installing John use unshadow as followes,

sudo unshadow /etc/passwd /etc/shadow > $HOME/pwd.txt

Data you need will be in a text file named pwd.txt in your home folder.

  • 1
    This answer is correct but I can not install john because of security issue, want to use only existing bash commands. – snoop Dec 27 '14 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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