Last active
April 7, 2024 13:50
-
-
Save alexolinux/747eb61c75cb2e39e2babfedd4f72dfe to your computer and use it in GitHub Desktop.
Create a devops user with small customizations
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 | |
USER="<ADD-THE-USER-HERE!!!>" | |
PUBLIC_KEY="<ADD-THE-PUBLIC-KEY-HERE!!!>" | |
# Function to display a fancy message | |
fancy_echo() { | |
printf "\n\e[1;36m%s\e[0m\n" "$1" | |
} | |
fancy_echo "Updating and installing required packages..." | |
yum -y update && yum -y install epel-release zsh util-linux-user vim-enhanced | |
fancy_echo "Creating a new group named devops..." | |
groupadd --gid 2024 devops | |
fancy_echo "Creating a new user with the specified username, home directory, and adding to the devops group..." | |
useradd -m -g devops $USER | |
fancy_echo "Allowing members of the devops group to run sudo without a password..." | |
echo "%devops ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers.d/devops | |
fancy_echo "Changing the user's shell to Zsh..." | |
chsh --shell $(which zsh) $USER | |
fancy_echo "Adding SSH public key to authorized_keys..." | |
mkdir -p /home/$USER/.ssh | |
echo "$PUBLIC_KEY" > /home/$USER/.ssh/authorized_keys | |
chmod 700 /home/$USER/.ssh | |
chmod 600 /home/$USER/.ssh/authorized_keys | |
chown -R $USER:devops /home/$USER/.ssh | |
fancy_echo "Setup completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment