There are plenty of people that already answered to the question "how to execute useradd properly in a script?"
My question is: "is it possible to tell to useradd to execute one script when it is called?"
I am writing a script to push identities files (ssh-keys) in an HPC cluster when a user is created, but I think the "cleanest" way would be to write a script that is executed by useradd.
The script should do something like this:
#!/bin/bash # sshpush.sh # # a script to SSH without passwords around the cluster nodes mkdir $HOME/.ssh cd $HOME/.ssh ssh-keygen -q cat id_rsa.pub >> authorized_keys cat > config <<EOF StrictHostKeyChecking no FallBackToRsh no BatchMode yes ConnectionAttempts 5 UsePrivilegedPort no Compression no Cipher blowfish CheckHostIP no EOF cpush /etc/passwd cpush /etc/shadow cpush /etc/groups
notice that the /home directory is mounted as NFS on all nodes.
Ideally, the script should be executed at the end of the user creation process, after that
$HOMEis created and that the user as a valid group and id.