
我的 .profile 檔案中有以下腳本:
systemctl is-active --quiet lightdm && (
echo Welcome to Terminal) || (
sleep 8
startx)
fi
目標是如果 GUI 尚未運行,它將啟動 GUI。然而它從來沒有這樣做。它甚至從未說過「歡迎來到終端」。
編輯:我嘗試向 /etc/sudoers 添加規則,但它沒有更改提示。這是我在文件中的內容:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
lukaka ALL = NOPASSWD: /usr/sbin/service lightdm *
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
答案1
添加到末尾~/.profile
文件:
systemctl is-active --quiet lightdm && {
echo 'Welcome to Terminal'
} || {
echo 'Starting Desktop GUI in 8 seconds... Press Ctrl-c to abort'
sleep 8
sudo systemctl start lightdm
}
如果您的 LinuxMint 已設定為啟動到控制台而不是桌面,那麼在登入您的帳戶後您將看到訊息:
8 秒內啟動桌面 GUI...按 Ctrl-c 中止
若要中斷桌面加載,請按 -Ctrl+c 否則系統將要求您輸入密碼,如果您通過授權,則桌面 GUI 將啟動。
如果您已經加載桌面並啟動終端程序,它將向您顯示歡迎訊息:
歡迎來到航廈
聚苯乙烯
如果您不想提供sudo
自動桌面啟動的密碼,請執行以下操作:
1. 運行sudo visudo
並提供您的密碼。
2. 如果您不想sudo
到處使用密碼打擾您,請
在文件末尾添加:(替換您的實際用戶名而不是您的使用者名稱)
YourUserName ALL=(ALL) NOPASSWD: ALL
並保存。否則,您可以使用以下行繞過僅
輸入密碼來啟動桌面的要求:sudo
visudo
YourUserName ALL = NOPASSWD: /usr/sbin/service lightdm *