如何在GDM登录屏幕上隐藏用户?


64

我最近添加了一些qmail所需的新用户。现在,它们出现在登录屏幕的框中并混乱了,我必须滚动查找我的用户。如何在登录框中隐藏那些用户?


我不知道是否追加Exclude=foobar/etc/gdm/gdm.conf作品中,你试过吗?
Umang 2010年

好问题,答案可能已经过时(根据meta的讨论)。
Thufir

Answers:


30

编辑文件/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工具来执行此操作,但在最近的几个发行版中还没有使用过。

另一种选择是将用户的UID设置为1000以下。那些也被认为是系统帐户,这些帐户也未包含在GDM问候程序中。


afaik,由于GDM已从用于配置的平面文本文件切换到Gconf模式,因此GUI工具不再起作用。
LassePoulsen

感谢您提供信息源实验室。我注意到在最近的几个发行版中,由于类似的原因,一些GUI工具已经丢失。
理查德·霍洛威

29
实际上,我认为您不应该进行修改/etc/gdm/gdm.schema。而是将这两行添加[greeter] Exclude=nobody,qmail-foo,qmail-bar/etc/gdm/custom.conf。(除了之外nobody,默认列表中的名称不会显示,因为它们的uid <1000。)
Gilles 2010年

3
通常,您应该为此使用小于1000的uid。
txwikinger 2010年

@RichardHolloway在中找不到这样的文件Ubuntu 12.04.04,您能建议吗?
gotqn 2014年

56

对于较新的GDM 3.X,旧答案不起作用,但该答案除外。中
greeter设置custom.conf过时,即它将不再起作用。如果要避免更改用户的uid,可以采用一种简单的解决方法:

  1. 打开终端,然后输入(用user您要从登录屏幕隐藏的用户名替换):

    sudo nano /var/lib/AccountsService/users/user
    
  2. 将以下内容添加到文件中:

    [User]  
    Language=   
    XSession=gnome  
    SystemAccount=true  
    
  3. 切换用户或注销以测试是否user不再列出。


1
确实,这是我在阅读Arch文档后所做的。应该赞成这个答案,以便人们早日看到它并节省一些时间。
Stefan van den Akker,2015年

似乎是适当的方法,而不是操纵UID
xuma202 '16

1
太棒了!这有助于解决uid小于1000的用户在登录屏幕上被隐藏的问题。
biocyberman

1
使用户成为系统帐户的后果是什么?
Jistanidiot

2
这对我有用,但是我必须重新启动才能使更改生效。
benjer3

13

Hacky,但是您可以修改用户的ID,以使其不会显示在列表中:

sudo usermod -u 999 <username>

之所以可行,是因为ID小于1000的用户被视为“系统”用户(即非人类)。

我知道的唯一另一种方法是完全隐藏列表:

sudo -u gdm gconftool-2 --type bool --set /apps/gdm/simple-greeter/disable_user_list 'true'

3
没有“用户级别”之类的东西,它是用户的id。
若奥·平托

6
这个usermod -u选项很有趣:它会自动更改主目录中的uid和邮件假脱机(如果有)以匹配。但是,这可能会破坏他们对自己主目录之外所有文件的访问权限。
poolie 2011年

要完全隐藏列表,您还可以运行gdmsetup并使用复选框。
belacqua

11

详细介绍了吉尔斯(Gilles)对已接受答案的评论,这就是我认为目前做到这一点的“最佳实践”(“侏儒安全”)方式。此更改还将反映在Gnome“指示器Applet会话”中。

这种方法是GDM网站上的文档中建议的一种方法,尽管该站点和Gilles都在排除项中添加了“ nobody”,但我想确保很明显这实际上是必要的(尽管联机帮助页有什么内容)或明确提供的在线文档)。我已经在几个10.10系统上对此进行了测试,以验证可重复性。

我们要做的就是对进行单行编辑/etc/gdm/custom.conf。不建议使用其他大多数方法(对default.conf,gdm.conf等进行更改)。

如果您现有的/etc/gdm/custom.conf,请编辑该文件。否则,复制示例文件:

sudo cp /usr/share/doc/gdm/examples/custom.conf /etc/gdm/custom.conf

在的[Greeter]部分中/etc/gdm/custom.conf,添加:

Exclude=user1,user2,nobody

其中“ user1”和“ user2”是您不希望在GDM“面部浏览器”上显示的用户名或passwd文件条目(例如qmail,squid等)。

注意:在我的Gnome / GDM版本(2.30)下,如果“排除”条目中未列出“ nobody”,则将nobody显示伪造的登录用户,而不是user1或user2。

NB#2:不显示UID低于1000的帐户是可配置的参数。默认情况下,该MinimalUID值设置为1000。仅当默认设置IncludeAll=true保留Include不变且伪指令未更改为非空值时,GDM迎接者才会扫描passwd文件以查找UID大于MinimalUID的条目。然后显示排除列表中没有UID高于MinimalUID的用户。

我还没有测试过反向设置(即Include=user1,user2在custom.conf 中设置一个条目)是否可以按所示方式工作。它应覆盖任何IncludeAll设置,并仅显示明确列出的用户。


+1以引用GDM的网站,因为这对我有用。
亚伦2012年

在新版本的GDM上不再起作用。
Stefan van den Akker,2015年

2

我这个周末写了一个脚本(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

2

我必须同意,这里最被接受的答案是接近的,但还不能确定。

我只是自己舔了一下这个问题,对我来说,答案是更改以下gdm.schema条目:

(original)
<schema>
      <key>greeter/IncludeAll</key>
      <signature>b</signature>
      <default>true</default>
    </schema>

(after my edit)
<schema>
      <key>greeter/IncludeAll</key>
      <signature>b</signature>
      <default>false</default>
    </schema>

这样的结果是所有用户列表都被禁用,如果我正确地解释了原始问题,这实际上就是OP(gruszczy)打算做的事情。由于无需更改此设置,所有用户ID(无论UID号码如何)都将被排除,因此无需进行冗长的排除。我个人已将此设置应用于3个单独的CentOS 6.2服务器,这些服务器在工作时偶尔通过RDP通过XDMCP(使用xrdp> vnc-server> xinetd> gdm> gnome)进行访问,这使我们一些经验不足的Linux管理员可以在这些服务器上工作最少培训的系统。

所有这些都说明了这一点,尽管我确实同意经验不足的系统管理员应该从一开始就从一个个人帐户(也许具有sudo访问权限)而不是作为一个root来学习工作,但是如果您有使用该帐户的经验,那没有什么害处在这样做。只需确保事先知道自己在做什么。对于其他系统管理员,我向所有这些系统添加了对Active Directory的CentrifyDC支持,并对这些系统进行了配置,以便在维护用户的AD安全组权限的同时,将AD-UserID用于桌面会话。但是就我个人而言,由于我设计了所有这些服务器并且已经使用Linux超过15年,因此我认为使用root来加速工作没有任何意义。实际上,我倾向于在具有以下功能的系统上启用root用户:已被禁用,以便我可以使用该帐户来完成任务。实际上,最主要的事情就是养成在更改文件之前创建任何文件的备份副本的习惯。这样可以防止大多数事故,并允许您在执行编辑时恢复系统,否则将导致系统变得不可访问(只需启动到实时CD并修复需要修复的内容)。

恕我直言,我相信“永远都不以root用户身份登录”的口号实际上就是为了保护n00bie sysadmins免受自身攻击。但是,如果您达到了Linux的能力水平,可以在很短的时间内从任何Linux操作系统设计系统并且每次都能工作,那么就没有理由“永远不要以root用户身份登录”咒语是因为此时您已经准备好处理使用该帐户所带来的责任。在使用CentrifyDC提供AD支持的环境中尤其如此,因为“ root”成为本地sysadmin帐户,并且(通常)会自动启用。因此,我发现最好追根溯源,并设置root帐户的密码,这是我在当今任何部署中要做的第一批任务之一。当然,我可以整个“以自己的ID身份登录,然后进行sudo up”,但我个人并不认为需要那样做。您自己的里程可能会有所不同...


0

将用户登录Shell更改为/ etc / passwd中的空字符串

例如,更改:

# Change
example:x:2001:2001:Example User,,,:/home/example:/bin/bash

# To
example:x:2001:2001:Example User,,,:/home/example:

我重新启动了显示管理器,并观察到此生效。

sudo service lightdm restart
# (or gdm, mdm, ...)

我花了数周的时间才将其识别为用户隐藏在显示管理器登录问候语中的原因。显然,/ var / lib / AccountService / users被MDM忽略了,并且假定也被GDM忽略了。我没去,只要添加一个Exclude=user1,user2Include=user3[greeter]在/etc/mdm/mdm.conf,或创建一个/etc/mdm/custom.conf,作为另一个盒子躲在用户通过添加useradd就好了,而用户显示了添加adduser。将登录shell设置为/ bin / false会拒绝所有对该用户的登录,我仍然希望以此身份登录。但是,如果您希望普通用户无法访问该用户,这也会在登录屏幕中隐藏该用户。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.