Skip to content

Instantly share code, notes, and snippets.

@edgardmota
Created June 2, 2021 11:48
Show Gist options
  • Save edgardmota/a64ea391feac706aa9968a8d8c9d4be1 to your computer and use it in GitHub Desktop.
Save edgardmota/a64ea391feac706aa9968a8d8c9d4be1 to your computer and use it in GitHub Desktop.
caution_message (){
echo -e "
--------------------------------------------------------
CAUTION
--------------------------------------------------------
You are using a root user which is not a recommended
practice as those users have the potetial to cause
severe damages to the systems under many circunstances.
For being the most privileged accounts on Unix/Linux,
their use have to be restricted and avoided at all costs.
Every single command/program a root user fires inherites
its powerful permission on the system. That means that if
you fire a wrong command when logged as a root user or if
the program you're using does something it shouldn't for
any reason (a bug, an exploitation), it won't have any
restriction on what it could affect. Moreover, if you,
for any reason, let a system logged with a root user
without supervision, someone can have full power over it,
being able to cause damage on purpose or accidentaly.
----------------------------------------------------"
}
continue (){
echo -ne "\nProceed (y/n): " >&2
read answer
echo $answer | tr '[:upper:]' '[:lower:]' # Keeping lower canse of user answer
}
if [ `id -u` -eq $ROOT_USER_ID ]
then
caution_message
answer=$(continue)
while [ "$answer" != "y" -a "$answer" != "n" ] # Checking if user have answer 'y' our 'n'
do
echo -e "\nThe answer $answer is invalid. Answer just y or n."
answer=$(continue)
done
if [ "$answer" = "y" ] # Logging information of user who decides to proceed
then
username=`whoami`
echo -e "Timestamp: `date`" >> $LOG_DIRECTORY/$username
lslogins `whoami` >> $LOG_DIRECTORY/$username
exit 0
else
logout &>/dev/null # Works only on login shells
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment