Skip to content

Instantly share code, notes, and snippets.

@bzz
Created May 15, 2014 03:48
Show Gist options
  • Save bzz/b5d62bf3e1c08dca683d to your computer and use it in GitHub Desktop.
Save bzz/b5d62bf3e1c08dca683d to your computer and use it in GitHub Desktop.
Create a new user on a multiple linux machines
#!/bin/bash
#
# Creates new user with given passwd on the set of machines
hosts="$@"
total_created=0
for host in ${hosts}; do
ssh -t root@"${host}" <<'ENDSSH'
useradd PLACE-USER-HERE -p PLACE-ENCRIPTED-PASSWORD-HERE(i.e from /etc/shadow)
ENDSSH
if [[ "$?" -ne 0 ]]; then
echo "Unable to create new user on ${host}" >&2
else
((total_created++))
fi
done
echo "${total_created} users ceated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment