Last active
August 29, 2015 14:04
-
-
Save marshyski/61af2b8ad64ab99698af to your computer and use it in GitHub Desktop.
Adding Users Script
This file contains hidden or 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
#!/bin/bash | |
PASS=`cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 32 | head -n 1` | |
while read line; do | |
PASS=`cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 32 | head -n 1` | |
useradd -d /home/$line $line | |
echo "$PASS" | passwd --stdin $line 1> /dev/null | |
echo "$line ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers | |
mkdir -p /home/$line/.ssh | |
chmod 0700 /home/$line/.ssh | |
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0KhULPMPg+cn2CiTbTo0FfSK2azx1hpKFHqrtMCLsHzUvj7F7gmZsFSast2ZWQJgIP+Rs0N8O4n/Z/19QNOeWkYJNZTthZbnFPxZxqSXihkzFjYc1vfWqqdDsv4J7w4gLCY/l | |
FWQfLxf8bKnXlLZb1j2baU43X0BSu1IGZ9BQqBbNSYcxI0k3jTZ64XkCPfFu0huvLoPVuuAKfROy7uUBSW7ujLKWbXer4Fkmz58LqnPLvaEbJAGI1XBGRXOLZNY1J9bu/kqCwg4AJzjF8G5deqdy4YMmwhps8UrK0nIwGXYbkgqAWqhPcx | |
uKTn7rkWnG2duqlApBgftFc1oTsDcj' > /home/$line/.ssh/authorized_keys | |
chown -Rf $line /home/$line/.ssh | |
chown -Rf $line /home/$line/.ssh/* | |
chmod 0600 /home/$line/.ssh/* | |
echo "$line $PASS" | |
done < users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment