Ubuntu取消开机用户自动登录

注:配置前请先设置登录密码,不同显示管理器配置方法不同,可用命令查看:cat /etc/X11/default-display-manager

一、LightDM 显示管理器,关闭 Ubuntu 系统用户自动登录

  1. 查找自动登录配置文件,可以看到类似 autologin.conf 的文件
sh 复制代码
find / -iname "*autologin.conf*"

/etc/lightdm/lightdm.conf.d/20-autologin.conf
  1. 找到文件中以下几行,将 autologin-user=teamhd 改为 autologin-user= 然后重启验证
sh 复制代码
[Seat:*]
user-session=Lubuntu
autologin-user=
  1. 可用 sed 命令一键配置,然后重启验证
sh 复制代码
关闭: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.conf

sudo systemctl restart lightdm

二、GDM 显示管理器,关闭 Ubuntu 系统用户自动登录

  1. 查找自动登录配置文件,可以看到类似于以下名称的文件
sh 复制代码
find / -iname "*custom.conf*"

/etc/gdm3/custom.conf
  1. 找到文件中以下几行,将 AutomaticLoginEnable = true 改为 false 然后重启验证
sh 复制代码
[daemon]
AutomaticLoginEnable = false
AutomaticLogin = teamhd
  1. 可用 sed 命令一键配置,然后重启验证
sh 复制代码
关闭:sudo sed -i 's/^AutomaticLoginEnable *= *true/AutomaticLoginEnable=false/' /etc/gdm3/custom.conf

开启:sudo sed -i 's/^AutomaticLoginEnable *= *false/AutomaticLoginEnable=true/' /etc/gdm3/custom.conf

sudo systemctl restart gdm

三、特殊情况(没有自动登录配置文件)

  1. 如果没找到类似文件名的配置文件,则手动创建并添加内容,例如 20-autologin.conf
sh 复制代码
sudo vim /etc/lightdm/lightdm.conf.d/20-autologin.conf
  1. 在文件中添加以下内容来关闭自动登录,然后重启验证
sh 复制代码
[Seat:*]
autologin-user=
  1. 在文件中添加以下内容来开启自动登录,然后重启验证
sh 复制代码
[Seat:*]
autologin-user=teamhd
相关推荐
chlk12313 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑14 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件14 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统