First, if the root password is not set, first set the password of the root user: sudo passwd root
One command to open all documents that need to be modified:
sub /root/.profile /etc/pam.d/gdm-autologin /etc/pam.d/gdm-password /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf /etc/gdm*/custom.conf
1. Modify the /root/.profile file
mesg n || true
Change totty -s && mesg n || true
2. Modify the gdm-autologin gdm-password file
Comment out the following lines in /etc/pam.d/gdm-autologin and /etc/pam.d/gdm-password respectively:
#auth required pam_succeed_if.so user != root quiet_success
3. Modify and modify the 50-ubuntu.conf file
Add two lines at the end of /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf:
greeter-show-manual-login=true
allow-guest=false
4. Password-free login settings
Modify /etc/gdm/custom.conf or /etc/gdm3/custom.conf file
AutomaticLoginEnable=True
AutomaticLogin=root
Save and restart