Last active
June 13, 2017 21:06
-
-
Save namuan/d75f08cdc8fee89ce2fd to your computer and use it in GitHub Desktop.
Create user with admin
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
# check directory permissions 755 (.ssh) 644 (.ssh/authorized_keys) | |
#!/bin/bash | |
if [ "$(id -u)" != "0" ]; then | |
echo '** Script must be run as root **' | |
exit 1 | |
fi | |
if ! /bin/egrep -i "^admin\:" /etc/group &>/dev/null; then | |
echo "Creating the admin group" | |
groupadd admin | |
fi | |
if ! /bin/egrep -i "^%admin ALL" /etc/sudoers &>/dev/null; then | |
echo "Allowing sudo access for the admin group" | |
cat <> /etc/sudoers | |
# Members of the admin group may gain root privileges | |
%admin ALL=(ALL) ALL | |
EOF | |
fi | |
if ! /bin/egrep -i "imon" /etc/passwd &>/dev/null; then | |
echo "Creating the user" | |
# to generate an encrypted password for useradd: | |
# perl -e 'print crypt("s3cr3t", "password"),"\n"' | |
useradd -d /home/imon -s /bin/bash -G admin -p $(perl -e'print crypt("s3cr3t", "password")') -m imon | |
# cp -r ~/.ssh /home/foundry/ | |
# chown -R imon:imon /home/imon/.ssh | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment