Skip to content

Instantly share code, notes, and snippets.

@a-reda
Created March 15, 2026 17:54
Show Gist options
  • Select an option

  • Save a-reda/94d980d62c3a24f727859adc1ae4a6e4 to your computer and use it in GitHub Desktop.

Select an option

Save a-reda/94d980d62c3a24f727859adc1ae4a6e4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Configuration
NEW_USER="MY_NEW_USER"
PASSWORD="MY_PASSWORD"
# 1. Update system
apt update && apt upgrade -y
# 2. Install Sudo and OpenSSH Server
apt install sudo openssh-server -y
# 3. Create user and add to sudo group
# -m creates the home directory, -s sets the shell
useradd -m -s /bin/bash "$NEW_USER"
echo "$NEW_USER:$PASSWORD" | chpasswd
usermod -aG sudo "$NEW_USER"
# 4. Enable and start SSH
systemctl enable ssh
systemctl start ssh
# 5. Basic SSH Security (Optional but recommended)
# This allows the new user to login via SSH
sed -i 's/^#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
# Restart SSH to apply changes
systemctl restart ssh
echo "Setup complete! User '$NEW_USER' created with sudo access."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment