2

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.

1

It looks that that isn't an option here (Fedora 19, shadow-utils-4.1.5.1-5.fc19). It sounds like a very useful extension, though. Please report this as a request for enhancements in your distribution's bugtracker (or where that should go).

  • mmmh, It seems like it isn't. I have looked in the source code of Useradd and I don't see anything like that. This is sad. Maybe I try to write it once I got a few hours... – Danduk82 Feb 7 '14 at 8:26
  • Does the skel directory (files to add to a new account) help? – vonbrand Feb 7 '14 at 17:20
0

I haven't done a lot of testing with your case, but sometimes you can use alias command= to change what command does. Try it with ls first and play around with it to learn how aliasing can work. When you're done, just say unalias ls and the shell builtin will resume working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.