![如何在 GDM 登录屏幕上隐藏用户?](https://linux22.com/image/976368/%E5%A6%82%E4%BD%95%E5%9C%A8%20GDM%20%E7%99%BB%E5%BD%95%E5%B1%8F%E5%B9%95%E4%B8%8A%E9%9A%90%E8%97%8F%E7%94%A8%E6%88%B7%EF%BC%9F.png)
我最近添加了几个 qmail 所需的新用户。现在他们出现在登录屏幕的框中,使屏幕变得混乱,我必须滚动才能找到我的用户。我怎样才能在登录框中隐藏这些用户?
答案1
对于较新的 GDM 3.X,旧的答案不起作用,除了这个greeter
中的 设置custom.conf
是过时的,也就是说它将不再起作用。如果你想避免更改用户的 uid,有一个简单的解决方法:
打开终端,然后输入(替换
user
为您要在登录屏幕上隐藏的用户名):sudo nano /var/lib/AccountsService/users/user
将以下内容添加到文件:
[User] Language= XSession=gnome SystemAccount=true
切换用户或注销以测试是否
user
不再列出。
答案2
编辑文件 /etc/gdm/gdm.schema 找到当前如下所示的部分:
<schema>
<key>greeter/Exclude</key>
<signature>s</signature>
<default>bin,root,daemon,adm,lp,sync,shutdown,halt,mail,news,uucp,operator,nobody,nobody4,noaccess,postgres,pvm,rpm,nfsnobody,pcap</default>
</schema>
例如,为了排除名为 qmail 的用户,请将 qmail 添加到默认列表,因此该部分如下所示。
<schema>
<key>greeter/Exclude</key>
<signature>s</signature>
<default>qmail, bin,root,daemon,adm,lp,sync,shutdown,halt,mail,news,uucp,operator,nobody,nobody4,noaccess,postgres,pvm,rpm,nfsnobody,pcap</default>
</schema>
这将阻止用户 qmail 出现在 gdm 欢迎窗口中。以前有一个不错的 GUI 工具可以执行此操作,但在最近的几个版本中,Ubuntu 中已不再有该工具。
另一种选择是将用户的 UID 设置为 1000 以下。这些被视为系统帐户,也被排除在 GDM 欢迎程序之外。
答案3
虽然有点儿黑客,但你可以修改用户的 ID,这样他们就不会显示在列表中:
sudo usermod -u 999 <username>
这是有效的,因为 id 低于 1000 的用户被视为“系统”用户(即不是人类)。
我知道的唯一其他方法是完全隐藏列表:
sudo -u gdm gconftool-2 --type bool --set /apps/gdm/simple-greeter/disable_user_list 'true'
答案4
这个周末我写了一个脚本(gdm-greeter)。它在 CentOS 6.2 上运行良好,不知道它对 Ubuntu 是否有用?
#!/bin/bash
#
# $LastChangedDate: 2012-02-17 09:13:10 +0100 (Fri, 17 Feb 2012) $
# $Revision: 1627 $
#
# Get the default exlude list
DefaultExclude=`sed 's,</schema>,#,' /etc/gdm/gdm.schemas | \
tr '\n#' '#\n' | \
grep '>greeter/Exclude<' | tr '\n#' '#\n' | \
grep '<default>' | \
sed -e 's,.*<default>,,' -e 's,</default>.*,,'`
# Get the Exclude list from the config
eval `grep '^Exclude=' /etc/gdm/custom.conf 2> /dev/null`
# If empty copy the default
if [ "$Exclude" = "" ]
then
Exclude=$DefaultExclude
fi
# Collect all user accounts with a shell
Users="`grep 'sh$' /etc/passwd | awk -F: '{print $1}' | \
sort | tr '\n' ',' | sed 's/,$//'`"
#------------------------------------------------------------------------------
# The functions area
PlaceExclude() # $1 new exclude string
{
# Create a .bak file
if [ ! -f /etc/gdm/custom.conf.bak ]
then
cp /etc/gdm/custom.conf /etc/gdm/custom.conf.bak
fi
# Create a tmp file without the Exclude string
cat /etc/gdm/custom.conf | tr '[\n' '\n[' | \
sed -e 's/^\(greeter[]].*\)[[]Exclude=[^[]*\([[].*\)/\1\2/' | \
tr '[\n' '\n[' > /tmp/custom.conf.$$
# If the tmp file is there and we have non default Exclude
if [ -f /tmp/custom.conf.$$ ]
then
if [ "$1" = "$DefaultExclude" ]
then
cat /tmp/custom.conf.$$ > /etc/gdm/custom.conf
else
# Place the new Exclude string
cat /tmp/custom.conf.$$ | tr '[\n' '\n[' | \
sed -e "s/^greeter[]][[][[]/greeter][Exclude=$1[[/" | \
tr '[\n' '\n[' > /etc/gdm/custom.conf
fi
fi
rm -f cat /tmp/custom.conf.$$
}
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Command area
add() # Cmd (Add a user to the greeter {<user>
{
UserFilter=`echo $Users | sed 's/,/|/g'`
if ! echo $1 | egrep -w $UserFilter &> /dev/null
then
echo "Error: user $1 unknown"
echo
return 1
fi
# Only work with the users not in the default exclude list
Filter=`echo $DefaultExclude | sed 's/,/|/g'`
Hidden=`echo $Exclude | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
# Check if we need to do something
if ! echo $Hidden | tr ',' '\n' | grep -w $1 &> /dev/null
then
echo
echo "User $1 is not hidden"
echo
else
# Remove the user from the exclude
PlaceExclude "`echo $Exclude | tr ',' '\n' | grep -vw $1 | \
tr '\n' ',' | sed 's/,$//'`"
# Tell the action
echo "User $1 added to the greeter"
echo
fi
}
del() # Cmd (Delete/hide a user from the greeter {<user>
{
UserFilter=`echo $Users | sed 's/,/|/g'`
if ! echo $1 | egrep -w $UserFilter &> /dev/null
then
echo "Error: user $1 unknown"
echo
return 1
fi
# Check if we need to do something
if echo $Exclude | tr ',' '\n' | grep -w $1 &> /dev/null
then
echo
echo "User $1 is already excluded from the greeter"
echo
else
# Exclude the user
PlaceExclude "$1,$Exclude"
# Tell the action
echo "User $1 hidden from the greeter"
echo
fi
}
hide() # CMD (Delete/hide a user from the greeter {<user>
{
del $1
}
hidden() # Cmd (List the hidden users {
{
Filter=`echo $DefaultExclude | sed 's/,/|/g'`
Hidden=`echo $Exclude | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
if [ ${#Hidden} -eq 0 ]
then
echo "No hidden users"
echo
else
echo
echo "Users hidden from the greeter:"
echo
echo $Hidden | tr ',' '\n' | sed 's/^/ /'
fi
}
users() # Cmd (List the users in the greeter {
{
Filter=`echo $Exclude | sed 's/,/|/g'`
Greeters=`echo $Users | tr ',' '\n' | egrep -vw "$Filter" | tr '\n' ','`
if [ ${#Greeters} -eq 0 ]
then
echo "No users in the greeter"
echo
else
echo
echo "Users in the greeter:"
echo
echo $Greeters | tr ',' '\n' | sed 's/^/ /'
fi
}
list() # CMD (List the users in the greeter {
{
users
}
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Framework area
help() # Cmd (Command help {[command]
{
if [ "$1" = "" ]
then
CMD=help
else
CMD=$1
fi
if ! grep \^${CMD}*\(\).*#.*Cmd $0 > /dev/null 2>&1
then
(
echo
echo "Error: unknown cmd"
echo
) >&2
else
(
echo
echo "Usage: `basename $0` $CMD `grep \^${CMD}*\(\).*#.*Cmd $0 | \
sed 's/.* {//g'`"
echo
) >&2
fi
}
#
# Main
#
if [ "$1" != "" ] && grep -i $1\(\).*#.*Cmd $0 > /dev/null 2>&1
then
$*
else
echo
echo "Usage: `basename $0` command [parm1] [parm2] [..]"
echo
echo " Available Commands:"
echo
grep \^[0-9a-z_A-Z]*\(\).*#.*Cmd $0 | \
awk -F\( '{printf "%-16s %s\n",$1,$3}' | sed 's/ {.*//g' | sort
echo
fi