Script or Command to get all username

albsallu

Member


Messages: 60

I am not too good with unix. I need a script that will give me a result of all username, Display name, and password in a text file.

Thanks
 

ale

Daemon

Reaction score: 166
Messages: 1,059

You can try $ cat /etc/passwd | cut -d ":" -f 1
 
OP
OP
A

albsallu

Member


Messages: 60

It just give the username and not the display name and the password. I need something that could give me username together with the display name and/or the password
 

ale

Daemon

Reaction score: 166
Messages: 1,059

Uh, I didn't read the complete message.
That will give you only the usernames.
You can get the complete name using -f 5.
And about the password...
 

Oxyd

Active Member

Reaction score: 15
Messages: 166

You can't get the password easily. The passwords are stored in an encrypted form in the root-readable-only file /etc/master.passwd, encrypted with crypt(3).
 

phoenix

Administrator
Staff member
Administrator
Moderator

Reaction score: 1,260
Messages: 4,099

awk comes in handy for parsing text files that have a unique field separator. For /etc/passwd and /etc/master.passwd, the colon :)) is the field separator. So all you need to do is figure out which field(s) to print, and tell awk to print them:
Code:
# cat /etc/master.passwd | awk -F":" '{ printf "%s %s %s\n",$1,$5,$2 }'
That will print field 1 (username), field 5 (full name), and field 2 (password), as they are stored in /etc/master.passwd.

To make it look nicer, you can add labels:
Code:
# cat /etc/master.passwd | awk -F":" '{ printf "username: %s  name: %s  password: %s\n",$1,$5,$2 }'
 
Top