Skip to content

Instantly share code, notes, and snippets.

@dark-faze
Last active April 12, 2025 07:50
Show Gist options
  • Save dark-faze/869b02d61db2cece63da8a23bec6c827 to your computer and use it in GitHub Desktop.
Save dark-faze/869b02d61db2cece63da8a23bec6c827 to your computer and use it in GitHub Desktop.
Setup a new sudo user and no password login after launching the server.
# Create user
sudo adduser cj
# Set password expiry
sudo passwd -e cj
# Add to sudo group
sudo usermod -aG sudo cj
# Configure sudo access
echo "cj ALL=(ALL:ALL) ALL" | sudo tee /etc/sudoers.d/cj
# Create SSH directory
sudo mkdir -p /home/cj/.ssh
# Add the public key
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINBlfqermlV44zAU+iTCa5im5O0QWXid6sHqh2Z4L1Cm [email protected]" | sudo tee /home/cj/.ssh/authorized_keys
# Set correct permissions
sudo chmod 700 /home/cj/.ssh
sudo chmod 600 /home/cj/.ssh/authorized_keys
sudo chown -R cj:cj /home/cj/.ssh
# Update SSH config
sudo sed -i '/PermitRootLogin/d' /etc/ssh/sshd_config
sudo echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config
sudo sed -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sudo echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
sudo sed -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
sudo echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
# Restart SSH service
sudo systemctl restart ssh
# Disable kernel update prompts
echo "\$nrconf{kernelhints} = -1;" | sudo tee /etc/needrestart/conf.d/99disable-prompt.conf
# Update and upgrade
sudo apt update
sudo apt upgrade -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
sudo reboot
ssh cj@YOUR_SERVER_IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment