Created
February 6, 2025 23:00
-
-
Save devinatkin/85934dc15b818ef1de8272596d30957c to your computer and use it in GitHub Desktop.
Gotta add Santiago to the server, this is the one do to
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 | |
# Variables | |
USER="santiago" | |
USER_HOME="/home/$USER" | |
SSH_DIR="$USER_HOME/.ssh" | |
AUTHORIZED_KEYS="$SSH_DIR/authorized_keys" | |
GITHUB_KEYS_URL="https://github.com/Santigf12.keys" | |
SUDOERS_FILE="/etc/sudoers.d/$USER" | |
# Create user if not exists | |
if id "$USER" &>/dev/null; then | |
echo "User $USER already exists." | |
else | |
echo "Creating user $USER..." | |
sudo useradd -m -s /bin/bash "$USER" | |
fi | |
# Ensure the SSH directory exists | |
sudo mkdir -p "$SSH_DIR" | |
sudo chmod 700 "$SSH_DIR" | |
sudo chown "$USER:$USER" "$SSH_DIR" | |
# Fetch and set up authorized keys | |
echo "Fetching SSH keys from GitHub..." | |
curl -s "$GITHUB_KEYS_URL" | sudo tee "$AUTHORIZED_KEYS" > /dev/null | |
# Set correct permissions | |
sudo chmod 600 "$AUTHORIZED_KEYS" | |
sudo chown "$USER:$USER" "$AUTHORIZED_KEYS" | |
# Add user to sudo group | |
echo "Granting sudo privileges to $USER..." | |
sudo usermod -aG sudo "$USER" | |
# Allow sudo without password for convenience (optional, remove if not needed) | |
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee "$SUDOERS_FILE" > /dev/null | |
sudo chmod 440 "$SUDOERS_FILE" | |
echo "User $USER setup complete with SSH keys and sudo access." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment