greetd is a minimal, agnostic and flexible login manager daemon which does not make assumptions about what the user wants to launch, should it be console-based or graphical. Any script or program which can be started from the console may be launched by greetd, which makes it particularly suitable for Wayland compositors. It can also launch a greeter to start user sessions, like any other display manager.
安裝
安裝 greetd包 或 greetd-gitAUR。
默認配置文件位於 /etc/greetd/config.toml
。
PAM 相關的配置文件位於 /etc/pam.d/greetd
。
歡迎界面(Greeters)
Greetd 內置的默認歡迎界面是 greetd-agreety,這是一個最小化的實現。您可以考慮換成其他的歡迎界面:
- greetd-agreety — 默認的,基於文本的歡迎界面,類似於 agetty
- cosmic-greeter — 一個基於 libcosmic 的歡迎界面
- dlm — 一個基於 fbdev 的歡迎界面
-
ddlm — 一個基於 fbdev 的歡迎界面。
dlm
的改進/擴展版本
- gtkgreet — 一個基於 GTK 的歡迎界面
- ReGreet — 一個基於 GTK 的歡迎界面,支持不同的個性化選項,僅支持 Wayland
- wlgreet — 一個使用 Wayland 的歡迎界面
- tuigreet — 一個使用控制台 UI 的歡迎界面
- qtgreet — 一個基於 Qt 的歡迎界面
- nwg-hello — 一個用 Python 寫的基於 GTK3 的歡迎界面
啟動 greetd
啟用 greetd.service
,以便在啟動時啟動 greetd。
歡迎界面(Greeter)配置
在 /etc/greetd/config.toml
的 default_session
節中的 command
選項配置 greetd 運行的歡迎界面。若沒有做出更改,將使用內置的 agreety
歡迎界面。另請參閱 #agreety。
歡迎界面默認由 greeter
用戶運行,您可在配置文件的 default_session
節中的 user
選項更改用戶。將以下片段中的目標用戶改為您想使用的用戶:
... [default_session] user = "目标用户" ...
確保該用戶具有 /etc/greetd
目錄的所有權。
agreety
這是默認的歡迎界面。以下配置文件片段會讓 greetd 啟動 agreety:
... [default_session] command = "agreety --cmd $SHELL" ...
一旦用戶登錄,agreety 可以執行任意命令。例如,要啟動 Sway,將上例中的 $SHELL
改為 sway
。
gtkgreet
gtkgreet 需要一個混成器才能運行。要獲取完整體驗需要一個具有 wlr-layer-shell-unstable
支持的混成器,當然其他的也能用。例如,推薦使用 sway包,但是其他的一些如 cage包 也能用,下文提供了此二者的示例。
為指定 gtkgreet 可啟動的登錄環境,請在 /etc/greetd/environments
列出它們。
例如:
sway bash
您也可以為 gtkgreet 添加 -c mycommand
參數,將 mycommand 替換為所需程序(例如,gtkgreet -c bash
或 gtkgreet -c sway
)。根據所需在以下兩個混成器示例中執行該操作。
使用 cage
安裝 cage包 並按照以下片段配置 command
選項:
... [default_session] command = "cage gtkgreet" ...
使用 sway
安裝 sway包。請注意,使用 Sway 時,一旦用戶登錄,其必須被停止,為此您需要創建一個特定的配置文件。例如位於 /etc/greetd/sway-config
,具有以下內容:
# `-l` activates layer-shell mode. Notice that `swaymsg exit` will run after gtkgreet. exec "gtkgreet -l; swaymsg exit" bindsym Mod4+shift+e exec swaynag \ -t warning \ -m 'What do you want to do?' \ -b 'Poweroff' 'systemctl poweroff' \ -b 'Reboot' 'systemctl reboot' include /etc/sway/config.d/*
接下來,greetd 必須被設定為以上述配置文件運行 Sway。按照以下片段設置 command
選項:
... [default_session] command = "sway --config /etc/greetd/sway-config" ...
ReGreet
ReGreet 和 gtkgreet 一樣需要混成器,和 gtkgreet 一樣可以使用 Cage 和 Sway。只需將上述配置中的 gtkgreet 命令換成 regreet。對 sway 配置應當如此:
# Notice that `swaymsg exit` will run after ReGreet. exec "regreet; swaymsg exit" bindsym Mod4+shift+e exec swaynag \ -t warning \ -m 'What do you want to do?' \ -b 'Poweroff' 'systemctl poweroff' \ -b 'Reboot' 'systemctl reboot' include /etc/sway/config.d/*
ReGreet 從 /usr/share/xsession
(X11 會話)和 /usr/share/wayland-sessions
(Wayland 會話)選取可用的會話,因此無需在/etc/greetd/environments
中列出會話。
ReGreet can be configured through a TOML file in /etc/greetd/regreet.toml
. A sample file is provided in /usr/share/doc/greetd-regreet/regreet.sample.toml
with all available options. Copy this to /etc/greetd/regreet.toml
and make the changes you want, commenting out or deleting the lines you do not need. Any invalid options are ignored.
wlgreet
Wlgreet 需要一個具有 wlr-layer-shell-unstable
支持的混成器。配置類似於上文為 gtkgreet 設定 Sway,如下:
/etc/greetd/sway-config
exec "wlgreet --command sway; swaymsg exit" bindsym Mod4+shift+e exec swaynag \ -t warning \ -m '君欲何為?' \ -b '關機' 'systemctl poweroff' \ -b '重啟' 'systemctl reboot' include /etc/sway/config.d/*
tuigreet
tuigreet does not require any special setup, just set the command
option as follows:
... [default_session] command = "tuigreet --cmd sway" ...
tuigreet --help
will display customization options.
ddlm
ddlm does not require any special setup, just set the command
option as follows:
... [default_session] command = "ddlm --target sway" ...
qtgreet
In order to use qtgreet, you need a WLR based compositor (e.g. wayfireAUR, sway包).
Using Wayfire
Install wayfireAUR and set the command
option as follows:
... [default_session] command = "wayfire --config /etc/qtgreet/wayfire.ini" ...
The Wayfire configuration file referred to is included with qtgreet.
Using Hyprland
Set the command
option as follows:
... [default_session] command = "Hyprland --config /etc/greetd/hyprland.conf" ...
Then create /etc/greetd/hyprland.conf
as:
/etc/greetd/hyprland.conf
exec-once = qtgreet; hyprctl dispatch exit
nwg-hello
In order to use nwg-hello, you either need sway包 or hyprland包.
Using Sway
Install sway包 and set the command
option as follows:
... [default_session] command = "sway -c /etc/nwg-hello/sway-config" ...
The Sway configuration file referred to is included with nwg-hello.
Using Hyprland
Install hyprland包 and set the command
option as follows:
... [default_session] command = "Hyprland -c /etc/nwg-hello/hyprland.conf" ...
The Hyprland configuration file referred to is included with nwg-hello.
提示和技巧
自動登錄
要讓某用戶自動登錄,請在 /etc/greetd/config.toml
中定義 initial_session
節:
... [initial_session] command = "sway" user = "myuser" ...
command
選項可以是任意可執行文件,在上例中,系統啟動後會以 myuser
用戶運行 Sway。
若您不想用 greetd 且要使用自動登錄,請參閱autologin。
運行本地程序
將您的 PATH 添加到 ~/.profile
,否則 greetd 喚起的桌面環境將無法運行本地程序。Greetd 不會訪問 .bashrc
和 .zshrc
,因此不要在這兩個文件中設置 PATH。
~/.profile
export PATH="$HOME/.local/bin:$PATH"
設定環境
Greetd 默認不會設定環境變量如 XDG_SESSION_TYPE 和 XDG_CURRENT_DESKTOP 除非歡迎界面基於您設置的會話設定了環境變量(例如 TUI 會基於會話文件選擇的區域設定會話類型)。一種方案是在執行實際命令前用一個腳本設定需要的環境變量,例如要啟動 sway:
/usr/local/bin/start-sway
#!/bin/sh export XDG_SESSION_TYPE=wayland export XDG_SESSION_DESKTOP=sway export XDG_CURRENT_DESKTOP=sway # Wayland stuff export QT_QPA_PLATFORM=wayland export SDL_VIDEODRIVER=wayland export _JAVA_AWT_WM_NONREPARENTING=1 exec sway "$@"
然後讓歡迎界面運行該腳本,例如使用 gtkgreet
可以如此:
/etc/greetd/config.toml
... [default_session] command = "gtkgreet -c /usr/local/bin/start-sway" ...
或將 start-sway
置入 /etc/greetd/environments
。
參閱 How to Set XDG_SESSION_TYPE=wayland。
設定 logind 會話類型
The logind session type is set by the XDG_SESSION_TYPE environment variable. However, it must be set before the PAM session is opened. Because of this, setting the variable through ~/.profile
or a wrapper script will not work (both happen after session open).
The correct way to achieve this is through the environment variables sent by greeters (these are set before session open). So if your greeter supports it, just make it send the appropriate XDG_SESSION_TYPE=xxx.
If your greeter does not support this, it is also possible to use pam_env under the auth group. The drawback is that all the sessions spawned by greetd will use that session type, which may or may not be problematic depending on your use case.
Here is how one could use the pam_env method to have a Wayland session:
/etc/greetd/config.toml
[general] service = "greetd-spawn"
/etc/greetd/greetd-spawn.pam_env.conf
XDG_SESSION_TYPE DEFAULT=wayland OVERRIDE=wayland
/etc/pam.d/greetd-spawn
auth include greetd auth required pam_env.so conffile=/etc/greetd/greetd-spawn.pam_env.conf account include greetd session include greetd
缺失滑鼠指針
若您在一些類似於 wayfire
的混成器上使用 qtgreet
,您通常需要設置某些環境變量以使滑鼠指針正常工作,例如 WLR_NO_HARDWARE_CURSORS=1
。一種方案是創建一個可執行腳本並在 /etc/greetd/config.toml
中調用它:
/usr/local/bin/greetd-startup.sh
#!/bin/sh export WLR_NO_HARDWARE_CURSORS=1 exec wayfire --config /etc/qtgreet/wayfire.ini
/etc/greetd/config.toml
... [default_session] command = "/usr/local/bin/greetd-startup.sh" ...