chmod should be called before chown to avoid SUID and SGRP reset.