I am trying to change the max password days policy to 60 for a subset of existing users on my Busybox Linux OS. This is the represented as the 5th field in the /etc/shadow file.
e.g:
nobody:*:56789:0:99999:7:::
nfsnobody:*:56789:0:99999:7:::
user1:*:12345:0:99999:7:::
daemon:*:12345:0:99999:7:::
should end up as
nobody:*:56789:0:60:7:::
nfsnobody:*:56789:0:60:7:::
user1:*:12345:0:99999:7:::
daemon:*:12345:0:60:7:::
I have the following code snippet:
cp /etc/shadow /etc/shadow.tmp
LIST=”nobody nfsnobody daemon”
for USER in $LIST ; do
awk ‘BEGIN { OFS=FS = “:” } ; /^’$USER’/ { $5=60} {print} ’</etc/shadow.tmp > /etc/shadow
done
rm /etc/shadow.tmp
I feel like I am very close, but this only changes the last user in the list “daemon”; his 5th field gets set to 60, but nobody and nfsnobody do not.
e.g.:
nobody:*:56789:0:99999:7:::
nfsnobody:*:56789:0:99999:7:::
user1:*:12345:0:99999:7:::
daemon:*:12345:0:60:7:::
I'm not sure if/how awk needs to be tweaked or if Busybox is misbehaving.
BACKGROUND:
The Busybox Linux OS is stripped down to almost nothing (it only has an ash shell) and behaves differently then Redhat. Normally, I would use the "chage" command to fix this policy, but Busybox does not have a "chage" command so I have to do it by hand.
I tried using sed (which was fine on Redhat, but very strange on Busybox)
sed –e ‘/’$USER’/ s/[^:]*/60/5’ < /etc/shadow.tmp > /etc/shadow
and that also only changed the last USER, daemon
daemon:*:12345:0:99999:7:::
to
daemondaemondaemondeamondaemon60:*:12345:0:99999:7:::
I would appreciate any thoughts on this.
