Created
January 1, 2022 17:11
-
-
Save bennof/2c04fd29a97659e2ea7838609c77048d to your computer and use it in GitHub Desktop.
Disable root account on Ubuntu (should be default) and Debian
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/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