Sorting /etc/passwd and /etc/shadow files
Sorting /etc/passwd and /etc/shadow files
[root@server~]# cd /root/ [root@server~]# touch passwd.sorted shadow.sorted [root@server~]# chmod 644 passwd.sorted [root@server~]# chmod 600 shadow.sorted [root@server~]# sort -t: -n -k3,3 /etc/passwd >passwd.sorted [root@server~]# gawk -F: '{system("grep \"^" $1 ":\" /etc/shadow")}' passwd.sorted >shadow.sorted
[root@server~]# wc /etc/shadow shadow.sorted 211 211 10985 /etc/shadow 211 211 10985 shadow.sorted 422 422 21970 total [root@server~]# wc /etc/passwd passwd.sorted 211 413 11881 /etc/passwd 211 413 11881 passwd.sorted 422 826 23762 total
[root@server~]# cp -a /etc/passwd /root/passwd.`date -I` [root@server~]# cp -a /etc/shadow /root/shadow.`date -I` [root@server~]# mv passwd.sorted /etc/passwd && mv shadow.sorted /etc/shadow [root@server~]# restorecon -v /etc/passwd restorecon reset /etc/passwd context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:etc_t:s0 [root@server~]# restorecon -v /etc/shadow restorecon reset /etc/shadow context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:shadow_t:s0
Sorting /etc/group and /etc/gshadow files
[root@server~]# cd /root/ [root@server~]# touch group.sorted gshadow.sorted [root@server~]# chmod 644 group.sorted [root@server~]# chmod 600 gshadow.sorted [root@server~]# sort -t: -n -k3,3 /etc/group >group.sorted [root@server~]# gawk -F: '{system("grep \"^" $1 ":\" /etc/gshadow")}' group.sorted >gshadow.sorted
[root@server~]# wc /etc/group group.sorted 108 108 4435 /etc/group 108 108 4435 group.sorted 216 216 8870 total [root@server~]# wc /etc/gshadow gshadow.sorted 108 108 4133 /etc/gshadow 108 108 4133 gshadow.sorted 216 216 8266 total
[root@server~]# cp -a /etc/group /root/group.`date -I` [root@server~]# cp -a /etc/gshadow /root/gshadow.`date -I` [root@server~]# mv group.sorted /etc/group && mv gshadow.sorted /etc/gshadow [root@server~]# restorecon -v /etc/group restorecon reset /etc/group context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:etc_t:s0 [root@server~]# restorecon -v /etc/gshadow restorecon reset /etc/gshadow context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:shadow_t:s0
From http://www.typinganimal.net/wp/2013/10/31/sort-your-etcpasswd-and-etcshadow-files/