2

Hey I'm working on this all purpose script to tighten a ubuntu computers security and one of the things in it is to disable guest account through lightdm.conf. The way my script is setup or at least I want it to be setup is that if it doesn't find lightdm.conf it will make the file and insert the text. Any help would be appreciated.

#!/bin/bash
read -p "Disable guest account? yes or no: " ans
case "$ans" in
        yes) if locate /etc/lightdm/ |grep lightdm.conf
then         
                sed -i '$ a [SeatDefaults]' /etc/lightdm/lightdm.conf &&
                sed -i '$ a user-session=ubuntu' /etc/lightdm/lightdm.conf &&
                sed -i '$ a greeter-session=unity-greeter' &&
                sed -i '$ a allow-guest=false' /etc/lightdm/lightdm.conf &&
                echo "Guest account disabled succesfuly"

else cat > /etc/lightdm/lightdm.conf
                sed -i '$ a [SeatDefaults]' /etc/lightdm/lightdm.conf &&
                sed -i '$ a user-session=ubuntu' /etc/lightdm/lightdm.conf &&
                sed -i '$ a greeter-session=unity-greeter' &&
                sed -i '$ a allow-guest=false' /etc/lightdm/lightdm.conf && echo "Guest account disabled"

fi
        ;;
        no) echo "Will not disable guest account "
esac
A.B.
  • 92,125
oso9817
  • 21
  • 4

1 Answers1

4

Unnecessarily complicated. Please take a look at the documentation, which suggests that a separate file is created for the purpose.

To disable:

sudo sh -c 'printf "[Seat:*]\nallow-guest=false\n" >/etc/lightdm/lightdm.conf.d/50-no-guest.conf'

To re-enable:

sudo rm /etc/lightdm/lightdm.conf.d/50-no-guest.conf

It may be worth mentioning that the guest session feature is disabled by default in 16.10+.