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.
  • 90,397
oso9817
  • 21
  • 4
  • sed is a scripting language. Invoking it four times to execute four commands is incredibly inelegant and inefficient, especially if you rewrite the output file at each stage. You separate commands with newlines or semicolons, or pass in multiple -e options. For example, sed -i -e 's/foo/bar/' -e '234q' filename – tripleee Nov 30 '15 at 06:14

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+.

Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94