注:配置前請先設置登錄密碼,不同顯示管理器配置方法不同,可用命令查看: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