From: Frank Brehm Date: Fri, 22 Apr 2022 12:59:23 +0000 (+0200) Subject: Adding scripts/manage-users X-Git-Tag: 0.4.2^2~5^2~16 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=6de33dacd1ce70b22f6c6b756f15e3a76b4cb614;p=pixelpark%2Fpp-admin-tools.git Adding scripts/manage-users --- diff --git a/scripts/manage-users b/scripts/manage-users new file mode 100755 index 0000000..300eb24 --- /dev/null +++ b/scripts/manage-users @@ -0,0 +1,61 @@ +#!/bin/bash + + +for user in $(ls -1 /home ); do + + if [[ -d "/home/${user}" ]] ; then + + echo + echo "Performing user: ${user}" + + sudo_name=$( echo "${user}" | sed -e 's/\./_/g' ) + sudo_file="/etc/sudoers.d/10_${sudo_name}" + ak_file="/home/${user}/.ssh/authorized_keys" + mailbox="/var/mail/${user}" + + if [[ -f "${sudo_file}" ]] ; then + echo "Removing '${sudo_file}' ..." + rm -v "${sudo_file}" + else + echo "File '${sudo_file}' does not exists." + fi + + ak_file="/home/${user}/.ssh/authorized_keys" + + if [[ -f "${ak_file}" ]] ; then + echo "Removing '${ak_file}' ..." + rm -v "${ak_file}" + else + echo "File '${ak_file}' does not exists." + fi + + if [[ -f "${mailbox}" ]] ; then + echo "Removing '${mailbox}' ..." + rm -v "${mailbox}" + else + echo "File '${mailbox}' does not exists." + fi + + if getent passwd "${user}" ; then + echo "Removing user '${user}' ..." + userdel "${user}" + else + echo "User '${user}' does not exists." + fi + + sleep 0.5 + + fi + +done + +echo +echo "Performing group: 'pixel'" +if getent group 'pixel' ; then + echo "Removing group 'pixel' ..." + groupdel 'pixel' +else + echo "Group 'pixel' does not exists." +fi + +