Created
May 29, 2024 05:41
-
-
Save Rajan-sust/46ea1835fd8cee86e0fb4e00ef4fc24b to your computer and use it in GitHub Desktop.
Sudo non-root user creation in linux
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
#!/usr/bin/env bash | |
# ANSI color codes | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
RED='\033[0;31m' | |
username=$1 | |
fullname=$2 | |
password=$3 | |
echo ${username} | |
# Create the user | |
if adduser --disabled-password --gecos "${fullname}" "${username}"; then | |
echo -e "${GREEN}User ${username} created successfully.${NC}" | |
else | |
echo -e "${RED}Failed to create user ${username}.${NC}" | |
exit 1 | |
fi | |
# Set the password for the user | |
echo "${username}:${password}" | chpasswd | |
# add in sudo group | |
usermod -aG sudo "${username}" | |
# user info | |
echo -e "${GREEN}\xE2\x9C\x94${NC} Creation of a sudo non-root user done." | |
echo -e "Username: ${username}\nPassword: ${password}" | |
# SSH login | |
ip=$(curl -s ifconfig.me) | |
echo -e "SSH Login: ssh ${username}@${ip}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment