Skip to content

Instantly share code, notes, and snippets.

@JosiahKerley
Last active October 17, 2015 02:49
Show Gist options
  • Save JosiahKerley/0009423d597aa1987c1f to your computer and use it in GitHub Desktop.
Save JosiahKerley/0009423d597aa1987c1f to your computer and use it in GitHub Desktop.
Autologon tool for RHEL 7
#!/bin/bash
if [ ! -d ~/.autologon ]
then
mkdir -p ~/.autologon
fi
if [ "$1" == "enable" ]
then
cat /lib/systemd/system/getty@.service > ~/.autologon/lastexec
sed -i '/^ExecStart/s/ExecStart.*/ExecStart=-\/sbin\/agetty --autologin root --noclear %I/' /lib/systemd/system/getty@.service
if [ ! "$2" == "" ]
then
echo "#!/bin/bash" > ~/.autologon/runonce
echo "$2" >> ~/.autologon/runonce
echo 'sed -i "/~\/.autologon\/runonce/d" ~/.bashrc' >> ~/.autologon/runonce
echo 'rm -- "$0"' >> ~/.autologon/runonce
chmod +x ~/.autologon/runonce
sed -i '/~\/.autologon\/runonce/d' ~/.bashrc
echo '~/.autologon/runonce' >> ~/.bashrc
fi
elif [ "$1" == "disable" ]
then
cat ~/.autologon/lastexec > /lib/systemd/system/getty@.service
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment