fleet/ee/server/service/embedded_scripts/linux_lock.sh
Martin Angers 9082438580
Feature: Remote Lock for macOS, Windows and Linux (#16783)
Feature branch for the #9949  story.

---------

Co-authored-by: Jahziel Villasana-Espinoza <jahziel@fleetdm.com>
Co-authored-by: Roberto Dip <me@roperzh.com>
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
Co-authored-by: Sarah Gillespie <sarah@fleetdm.com>
2024-02-13 13:03:53 -05:00

32 lines
975 B
Bash

#!/bin/sh
# Disable automatic login for common display managers
disable_autologin() {
# GDM (GNOME Display Manager)
if [ -f /etc/gdm3/custom.conf ]; then
sed -i '/^AutomaticLoginEnable/s/^/#/' /etc/gdm3/custom.conf
sed -i '/^AutomaticLogin/s/^/#/' /etc/gdm3/custom.conf
fi
# LightDM
if [ -f /etc/lightdm/lightdm.conf ]; then
sed -i '/^autologin-user=/s/^/#/' /etc/lightdm/lightdm.conf
fi
# Add similar cases for other display managers if needed
}
# Disable automatic login
disable_autologin
# Loop through all users in /etc/passwd
awk -F':' '{ if ($3 >= 1000 && $3 < 60000) print $1 }' /etc/passwd | while read user
do
if [ "$user" != "root" ]; then
echo "Logging out $user"
pkill -KILL -u "$user" # Kill user processes. This will log out logged-in users.
passwd -l "$user" # Lock the user account
fi
done
echo "All non-root users have been logged out and their accounts locked."