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
相关推荐
ShirleyWang0125 分钟前
VMware如何导入vmdk文件
linux·数据库
Lueeee.29 分钟前
内核menuconfig配置实验
linux
遇见火星43 分钟前
常见Systemctl语句
linux·服务器·网络·systemctl
月明长歌1 小时前
【码道初阶】【LeetCode 110】平衡二叉树:如何用一个“Magic Number”将复杂度从O(N²)降为 O(N)?
linux·算法·leetcode
齐鲁大虾1 小时前
国产 Linux 系统核心优缺点与适用场景
linux·运维·服务器
skywalk81632 小时前
webvm 用浏览器启动的虚拟环境
linux·wasm
Awkwardx2 小时前
Linux网络编程—数据链路层
linux·运维·网络
kevin_水滴石穿2 小时前
在镜像生成时从内网获取字体安装包并配置
linux·docker·容器
liwenzhen20052 小时前
Linux OOM 问题之 DMSERVER 受害者
linux·运维·oom
大聪明-PLUS3 小时前
Linux 系统中的电池衰减
linux·嵌入式·arm·smarc