Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Secrets
- PORT=22
- ADMIN_USER=sadmin
- ADMIN_PASSWORD=sadminpassword
- # Functions
- append () {
- grep -q -F "$1" "$2" || echo "$1" >> "$2"
- }
- # change SSH port
- append "Port $PORT" /etc/ssh/sshd_config
- service ssh start
- # add admin user
- sudo su -c "useradd \"$ADMIN_USER\" -s /bin/bash -m"
- echo "$ADMIN_USER:$ADMIN_PASSWORD" | chpasswd
- # disable passwords for SUDO
- cp /etc/sudoers /tmp/sudoers.bak
- append "$ADMIN_USER ALL=(ALL) NOPASSWD:ALL" /tmp/sudoers.bak
- visudo -cf /tmp/sudoers.bak
- if [ $? -eq 0 ]; then
- cp /tmp/sudoers.bak /etc/sudoers
- else
- echo "Could not modify /etc/sudoers file. Please do this manually."
- fi
- # setup firewall
- ufw allow "$PORT"
- ufw --force enable
- ufw status
Add Comment
Please, Sign In to add comment