Created
January 31, 2012 00:20
-
-
Save versae/1707757 to your computer and use it in GitHub Desktop.
Setup script for virtual machines templates
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
#!/bin/bash | |
# Script to add a user to Linux system | |
# ------------------------------------------------------------------------- | |
read -p "Enter username: " username | |
read -s -p "Enter password: " password | |
echo "" | |
sudo egrep "^$username" /etc/passwd >/dev/null | |
if [ $? -eq 0 ]; then | |
echo "$username exists!" | |
exit 1 | |
else | |
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) | |
sudo useradd -d /home/$username -s /bin/bash -U -m -p $pass $username | |
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!" | |
fi | |
sudo usermod -a -G sudo $username | |
read -p "Enter a hostname: " host | |
sudo cp /home/template/.bashrc.template "/home/$username/.bashrc" | |
sudo chown $username "/home/$username/.bashrc" | |
sudo rpl "template" "$host" /etc/hosts | |
sudo hostname $host | |
sudo rm /etc/ssh/ssh_host_* | |
sudo dpkg-reconfigure openssh-server | |
sudo userdel -r -f template | |
kill -HUP $PPID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment