1754894 Members
3789 Online
108827 Solutions
New Discussion юеВ

gawk command

 
Ragni Singh
Super Advisor

gawk command

Hi all, can you please help me with a one liner in gawk that says chnage the /etc/shadow password field from a password to just a *.

thanks and points will be assigned.

Currently /etc/shadow looks like this...

odaos:$1$0rP21yM.$.NsFDQTtnnu7GE5qs84D/0:12492:0:99999:7:::

I want the 2nd field to be like such "*".
4 REPLIES 4
Stuart Browne
Honored Contributor

Re: gawk command

You actually want to modify the '/etc/shadow' file? or just a display of it with the password masked ?

If the first, then don't use awk, as it will require a temporary file and a move.

If you want to lock an account, then use the 'passwd -l ' command. This prefix's the encrypted password with an '!' which makes it invalid.

If it's just for displaying on the screen, then use something like:

awk 'BEGIN {FS=":";OFS=FS}{$2 = "*";print}' /etc/shadow

FS = field separator, OFS = output field separator.
One long-haired git at your service...
Muthukumar_5
Honored Contributor

Re: gawk command

You can try as,

perl -ni -e '@a=split /:/;$a[1]="*";$,=":";print @a;' /etc/shadow

Note: It will automatically change /etc/shadow file also. So try to backup /etc/shadow file as /etc/shadow.org

hth.
Easy to suggest when don't know about the problem!
Ragni Singh
Super Advisor

Re: gawk command

thanks but I still didn't get the answer I am looking for. Currently my /etc/shdow file has the password entry. I want to chnage this field to just a "*". This way users will be forced to authenticate to windows. I don't want a password in the 2nd field, I want a star * in that field.
Ivan Ferreira
Honored Contributor

Re: gawk command

Why don't you just use the usermod -L command to lock the users accounts?

Anyway, try this:

awk -F ":" -v OFS=":" '$2="*" { print $0 }' /etc/shadow
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?