Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0de09e8
commit d4dcb76
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/env bash | ||
|
||
# Add a new user, specify the UID so we can have the same UID across all machines | ||
# The password is hashed, encrypted, and needs to be single quoted to preserve the $ symbols | ||
# useradd -g usertom -G wheel,usertom -c "Tom Q. User" -u 505 -p '<somepassword>' usertom | ||
|
||
# Set the params here | ||
USER="michael" | ||
FULLNAME="'Mike Fiedler'" | ||
ID="505" | ||
PASSWORD='<somepassword>' # password is obtained from an existing system via: getent shadow $USER | cut -f2 -d":" | ||
|
||
# Add a bunch of servers to a server list variable | ||
SERVERLIST="localhost" | ||
|
||
function test_for_user { | ||
USERID=$(ssh $1 getent passwd $ID | cut -f2 -d":") | ||
if [ -z $USERID ] | ||
then | ||
echo "User ID $ID not found, you may proceed..." | ||
else | ||
echo "User ID $ID already exists on this system, exiting." | ||
exit | ||
fi | ||
USERNAME=$(ssh $1 getent passwd $USER | cut -f1 -d":") | ||
if [ -z $USERNAME ] | ||
then | ||
echo "User $USER not found, you may proceed..." | ||
else | ||
echo "User $USER already exists on this system, exiting." | ||
exit | ||
fi | ||
} | ||
|
||
function add_user { | ||
ssh $1 useradd -g $USER -G $USER,wheel -c $FULLNAME -u $ID -p \'$PASSWORD\' $USER | ||
This comment has been minimized.
Sorry, something went wrong. |
||
echo "Added user $USER to $1" | ||
} | ||
|
||
# Do it! | ||
for SERVER in $SERVERLIST; | ||
do | ||
echo "Working on $SERVER..." | ||
test_for_user $SERVER | ||
add_user $SERVER | ||
echo "Done!" | ||
done | ||
|
||
### END ### |
No need for $user on group here.