Ubuntu取消开机用户自动登录
注:配置前请先设置登录密码,不同显示管理器配置方法不同,可用命令查看:cat /etc/X11/default-display-manager
一、LightDM 显示管理器,关闭 Ubuntu 系统用户自动登录
- 查找自动登录配置文件,可以看到类似 autologin.conf 的文件
find / -iname "*autologin.conf*"/etc/lightdm/lightdm.conf.d/20-autologin.conf
- 找到文件中以下几行,将 autologin-user=teamhd 改为 autologin-user= 然后重启验证
[Seat:*]
user-session=Lubuntu
autologin-user=
- 可用 sed 命令一键配置,然后重启验证
关闭:sudo sed -i 's/^autologin-user=teamhd/autologin-user=/' /etc/lightdm/lightdm.conf.d/20-autologin.conf开启:sudo sed -i 's/^autologin-user=/autologin-user=teamhd/' /etc/lightdm/lightdm.conf.d/20-autologin.confsudo systemctl restart lightdm
二、GDM 显示管理器,关闭 Ubuntu 系统用户自动登录
- 查找自动登录配置文件,可以看到类似于以下名称的文件
find / -iname "*custom.conf*"/etc/gdm3/custom.conf
- 找到文件中以下几行,将 AutomaticLoginEnable = true 改为 false 然后重启验证
[daemon]
AutomaticLoginEnable = false
AutomaticLogin = teamhd
- 可用 sed 命令一键配置,然后重启验证
关闭:sudo sed -i 's/^AutomaticLoginEnable *= *true/AutomaticLoginEnable=false/' /etc/gdm3/custom.conf开启:sudo sed -i 's/^AutomaticLoginEnable *= *false/AutomaticLoginEnable=true/' /etc/gdm3/custom.confsudo systemctl restart gdm
三、特殊情况(没有自动登录配置文件)
- 如果没找到类似文件名的配置文件,则手动创建并添加内容,例如 20-autologin.conf
sudo vim /etc/lightdm/lightdm.conf.d/20-autologin.conf
- 在文件中添加以下内容来关闭自动登录,然后重启验证
[Seat:*]
autologin-user=
- 在文件中添加以下内容来开启自动登录,然后重启验证
[Seat:*]
autologin-user=teamhd