Skip to content

Instantly share code, notes, and snippets.

@bennof
Created January 1, 2022 17:11
Show Gist options
  • Save bennof/2c04fd29a97659e2ea7838609c77048d to your computer and use it in GitHub Desktop.
Save bennof/2c04fd29a97659e2ea7838609c77048d to your computer and use it in GitHub Desktop.
Disable root account on Ubuntu (should be default) and Debian
#!/bin/sh
# Disable root on Ubuntu/Debian
# (c) 2020-2021 Benjamin 'Benno' Falkner
##### NOT TESTET YET #####
set -e # halt on error, (debug add '-x')
cat <<EOF
Disable Root on Debian and Ubuntu
(c) 2020 Benjamin 'Benno' Falkner (MIT-License)
EOF
# Variables
# USER is a system variable should exist
# INSTALL SUDO
# function to install sodo command
install_sudo(){
echo "Please enter your root password."
su -c "apt-get install sudo" root || { echo "Please set all ."; exit 1}
}
# we can not expect sudo has been installed
test -n $(which sudo) || install_sudo
# check if user is in sudo group or add user to group (again the root password is needed)
groups | grep -w sudo || su -c "usermod -a -G sudo $USER" root & su - $USER
echo "sudo is now working for current user. Please use current user password form now on."
# disable root
sudo passwd -d root
sudo passwd -l root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment