X Window系统配置与安全详解
1. X系统基础配置文件
1.1 .xsession脚本与颜色设置
在某些情况下,若执行特定操作,会跳过单个
.xsession
脚本的执行。这在脚本损坏时非常重要,此时仅会定义一个
xterm
窗口,足以进行必要的修正。按下回车键表示密码输入结束,用户会话开始。
X系统中指定的各种颜色对于大多数显示器来说或多或少是合理的,若不合适也可进行调整。
COLOR
和
CLIENTHOST
是
xrdb
中预定义的变量之一。颜色可以通过常用名称(如红色、黑色、白色等)指定,也可以直接使用“RGB值”(以“#”字符开头并后跟数字)。服务器使用RGB颜色数据库(通常位于
/usr/lib/X11/rgb.txt
)将这些名称转换为合适的屏幕颜色。RGB值以十六进制数表示,每个字段(R、G和B)可以是一、二、三或四位数字。少于四位的字段会在每个数字后用零补齐。十六进制数字表示应显示的红色(R)、绿色(G)或蓝色(B)的量(零表示无,“ffff”表示全量)。
1.2 Xsession文件
Xsession
文件是用户登录后执行的脚本,这是一个系统范围的脚本,对该文件的每次修改都必须极其谨慎。若要自定义单个用户的会话,可使用
$HOME/.xsession
文件。该文件由主配置文件中该显示器的会话资源指向。
1.3 Xreset文件
Xreset
文件是会话终止后执行的脚本,该脚本并非必需,因此大多数情况下不会提供。有时会提供一个空脚本,以便在需要时进行自定义,示例如下:
$ cat /usr/lib/X11/xdm/Xreset
#!/bin/sh
#
# Xreset
#
# This program is run as root after the session terminates but
# before the display is closed
#
2. CDE配置文件
2.1 dtlogin守护进程启动
在系统启动期间,
dtlogin
程序作为守护进程启动,而非
xdm
。以下是Solaris 2.6和HP - UX 10.20的示例:
- Solaris 2.6:
$ ps -ef |grep "/usr/dt" | grep -v "grep"
root 1111 1 0 Jan 06 ? 0:00 /usr/dt/bin/dtlogin -daemon
- HP - UX 10.20:
$ ps -ef |grep "/usr/dt" | grep -v "grep"
root 1401 1381 0 Jan 5 ? 0:00 /usr/dt/bin/dtlogin
root 1381 1 0 Jan 5 ? 0:00 /usr/dt/bin/dtrc /usr/dt/bin/dtrc
dtlogin
守护进程在
dtrc
脚本中启动。
2.2 CDE配置文件目录与主配置文件
CDE配置文件位于
/usr/dt/config
目录(配置目录也可以是
/etc/dt/config
,默认情况下,CDT配置文件首先在此目录中检查,然后在
/usr/dt/config
中检查)。主配置文件重命名为
Xconfig
。
$ ls -F /usr/dt/config
C/ Xreset* cmsd.conf en_US.UTF-8/ sessionexit*
Xaccess Xservers
cz/ hu/ svc/
Xconfig
Xsession.d/ dtlogin.rc* images/ sys.dtprofile*
Xfailsafe* Xsession.ow*
dtspcdenv pl/ tr/
Xinitrc.ow Xsession.ow2*
dtterm.tc ru/ xfonts/
Xpasswd* Xsetup*
dtterm.ti sdtdict/
Xpasswd2* Xstartup*
el/ sessionetc*
2.3 dtlogin.rc脚本
dtlogin
守护进程在系统启动期间由
dtlogin.rc
脚本启动,示例如下:
$ cat /usr/dt/config/dtlogin.rc
#!/ bin/sh
#
# "@(#)dtlogin.rc.src 1.4 94/08/11
#
# This version of the dtlogin.rc script can be used on the Solaris(TM)
# operating system to initiate CDE tasks such as starting the dtlogin
# process.
#
# Common Desktop Environment
#
# (c) Copyright 1993, 1994 Hewlett−Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Novell, Inc.
#
# When placed in the /etc/rc2.d directory and named appropriately, such as
# "S99dtlogin", this script will automatically start the dtlogin window
# after the Solaris(TM) system boots to its multi−user level.
#
# This script is also called indirectly by the CDE dtconfig command.
mode=$1
# The argumant "start" and "stop" are used during the system startup and
# shutdown, and are of the interest here; the argument "reset" is used to
# recycle the dtlogin daemon, while the argument "update_printer" is used
# to update printers
#
usage_error(){
echo "$0 start (start dtlogin process)"
echo "$0 stop (stop dtlogin process)"
echo "$0 reset (reset dtlogin process)"
echo "$0 update_printers (update print actions)"
echo ""
}
# The definition of the functions "update_printers" and "login_server_pid" are skipped
case "$mode" in
'start')
update_printers # execute the function to update printers
if [ -x /usr/dt/bin/dtlogin ]; then
/usr/dt/bin/dtlogin -daemon&
# start dtlogin as a daemon
fi
;;
'stop')
# get dtlogin pid
dtlogin_pid='login_server_pid'
# get the PID of the dtlogin daemon
#
kill dtlogin process
if [ "$dtlogin_pid" != "" ]; then
/usr/bin/kill $dtlogin_pid
# stop the dtlogin daemon (kill the process)
fi
;;
'reset')
# get dtlogin pid
dtlogin_pid='login_server_pid'
# get the PID of the dtlogin daemon
# reset dtlogin process
if [ "$dtlogin_pid" != "" ]; then
/usr/bin/kill -HUP $dtlogin_pid # Recycle the dtlogin daemon
# (send the HUP signal)
fi
;;
'update_printers')
update_printers
# execute the function to update printers
;;
*)
usage_error
# otherwise excute the function
"usage_error"
exit 1
# (how to use the script)
;;
esac
exit 0
2.4 CDE主配置文件Xconfig
CDE主配置文件重命名为
Xconfig
,其用途不变,但内容反映了相对于
xdm
的变化。以下是
Xconfig
文件的部分内容:
$ cat /usr/dt/config/Xconfig
#############################################################################
#
# Xconfig
#
# Common Desktop Environment (CDE)
# Configuration file for the Login Manager
#
# $XConsortium: Xconfig.src /main/cde1_maint/5 1995/11/30 21:58:42 montyb $
#
# ************** DO NOT EDIT THIS FILE **************
#
# /usr/dt/config/Xconfig is a factory−default file and will be unconditionally overwritten upon
# subsequent installation. Before making changes to the file, copy it to the configuration directory,
# /etc/dt/config.
#
# This file contains behaviour resources for the CDE DT Login Manager. It also specifies the
# location of other configuration files used by the Login Manager.
#
# Appearance resources for the login screen are contained in the file
# specified by the "*resources" resource below.
#
# Most resources can be limited to a single display by including the display name in the resource.
# If the display name is not included, the resource will apply to all displays managed by the Login
# Manager. When specifying the display name, replace the ":" character in the name with an
# underscore "_". If the name is fully qualified, also replace dot "." characters with underscores.
#
# Example:
# Dtlogin*machine_domain_name_0*startup: /etc/dt/config/Xstartup.aa
#
# For more information see the man page, Dtlogin(1X).
#
############################################################################
Dtlogin.errorLogFile: /var/dt/Xerrors
Dtlogin.pidFile: /var/dt/Xpid
############################################################################
# Note: If you do not specify a full path beginning with a "/"
# dtlogin will first search for the following files in
# /etc/dt/config then in /usr/dt/config.
#
############################################################################
Dtlogin.accessFile: Xaccess
Dtlogin.servers: Xservers
Dtlogin*resources: %L/Xresources
Dtlogin*startup: Xstartup
Dtlogin*reset: Xreset
Dtlogin*setup: Xsetup
Dtlogin*failsafeClient: Xfailsafe
.....
.....
# Other resource entries follow
2.5 CDE配置文件简要说明
| 文件名称 | 说明 |
|---|---|
| Xservers | dtlogin明确管理的显示器列表 |
| Xresources | 指定登录屏幕外观的资源定义 |
| Xsetup | 以“root”身份在显示登录屏幕之前执行的脚本 |
| Xstartup | 用户成功认证后以“root”身份执行的脚本 |
| Xsession | 认证用户启动用户会话时执行的脚本 |
| Xfailsafe | 认证用户启动故障安全会话时执行的脚本 |
| Xreset | 用户会话退出后以“root”身份执行的脚本 |
2.6 Xservers文件
Xservers
文件用于配置所有由登录管理器启动或管理的X服务器。示例如下:
$ cat /usr/dt/config/Xservers
############################################################################
#
# Xservers
#
# Common Desktop Environment
#
# Configuration file for all Xservers started or managed by the Login Manager
# BEST TO NOT EDIT /usr/dt/config/Xservers directly.
#
# /usr/dt/config/Xservers is a factory−default file and will
# be unconditionally overwritten upon subsequent installation.
# Before making changes to the file, should copy it to the configuration
# directory, /etc/dt/config.
#
# @(#)Xservers.src 1.16 96/07/21
#
#################################################################################
#
# This file should contain an entry to start the X window server on the
# local workstation's display.
#
# If the local display has an associated character device, it should also
# be specified in the line. An example is the "console" device in the
# example line below. This allows Dtlogin to correctly monitor that device
# when [Command Line Login] mode is selected from the login screen.
#
# <HostName>:0 <class> local@console /usr/openwin/bin/X:0 <options>
#
# If no character device is associated directly with the display, then
# "none" should be specified.
#
# <HostName>:0 <class> local@none /usr/openwin/bin /X:0 <options>
#
# By default, the ":0" display is associated with the "/dev/console"
# character device. If the true console on the system is not the same
# as the ":0" graphics display, then the appropriate device or "none"
# should be specified for the ":0" display.
#
# An example need of "none" here would be a Sun system that had been
# configured to direct console I/O thru a tty port instead of using
# the workstation's display.
#
# If you want multiple−displays running dtlogin then make sure the
# connection number matches the display name, for example.
#
# <HostName>:1 local@none /usr/openwin/bin/X:1 <options>
#
# This means the X−server is started on connection number "1" and the
# display is connecting to the X−server on "1" through display name
# "LocalHost:1".
#
# If you have some X terminals connected which do not support XDMCP,
# you can add them here as well. Using XDMCP is recommended over
# entries in this file and should be used whenever possible.
#
# Example Syntax, the items between "< >" are optional:
#
# <HostName>:0 <class> local@console /usr/openwin/ bin/X:0 <options>
# <HostName>:1 <class> local@none /usr/openwin/bin /X:1 <options>
# XTermName:0 <class> foreign
#
# A "*" in the first field of the entry for a local server
# will be expanded to "<hostname>:0" by Dtlogin. This
# syntax is valid only within this file.
#
# * Local local@console /usr/openwin/bin/Xsun:0
#
# If the display type of "local_uid" is used, a user name such as "root"
# must follow in next field. In this example, by placing "root" here,
# Login will start a local Xserver under the user id of "root". On Sun
# system's this will give Xserver the ability to raise interactive
# scheduling priority of a client with mouse/keyboard focus to increase
# performance of the application.
#
#:0 Local local_uid@console root /usr/openwin/bin/Xsun:0
#
# In limited situations, the Xserver should not be run under a "root" id
# for security reasons. Examples are usually specific to Xserver
# extensions.
#
# On Sun Xservers one example involves the Display Postscript extension.
# If the DPS extension is granted access (via Xserver option line) to read
# and write Unix files via the "-dpsfileops" option (see Xsun man page) it
# should not be run under a "root" user id. For increaseced security,
# could instead run it as the "nobody" user.
#
#:0 Local local_uid@console nobody /usr/openwin/bin/Xsun:0 -dpsfileops
#
# Another example of interest here for Sun's Xserver is how to start on
# two or more screens. A two screen example follows.
#
#:0 Local local_uid@console root /usr/openwin/bin/X -dev /dev/fb0 -dev /dev/fb1
# See the Xsun.1 and Xserver.1 man pages for additional options of
# interest.
#
############################################################################
:0 Local local_uid@console root /usr/openwin/bin/Xsun:0 -nobanner
2.7 Xresources文件
Xresources
文件包含
Dtlogin
登录屏幕的外观和行为资源。该文件语法不同,注释行以“!”开头。部分内容示例如下:
$ cat /usr/dt/config/Xresources
!!########################################################################
!!
!! Xresources
!!
!! Common Desktop Environment
!! Configuration file for the Login Manager
!!
!! ************** DO NOT EDIT THIS FILE **************
!!
!! /usr/dt/config/Xresources is a factory−default file and will
!! be unconditionally overwritten upon subsequent installation.
!! Before making changes to the file, copy it to the configuration
!! directory, /etc/dt/config. You must also update the resources
!! resource in /etc/dt/config/Xconfig.
!!
!! $XConsortium: Xresources.src /main/cde1_maint/6 1995/12/01 14:04:59 rcs $
!!
!!#######################################################################
!!
!! This file contains appearance and behaviour resources for the Dtlogin
!! login screen. These are designed to be read into the root window
!! property via the 'xrdb' program. Dtlogin will do this automatically
!! after the server is reset and will remove them before the session
!! starts.
!!
!! Dtlogin contains internal default values for all resources. To
!! override a default value, uncomment the appropriate line below and
!! supply the desired value.
!!
!! Customization hints are included at the end of this file.
!!
!!########################################################################
!! Motif visuals
.....
.....
!!#######################################################################
!!# translations for the text field widget
.....
.....
!!#######################################################################
!! COLORS
.....
.....
!!########################################################################
!! FONTS
!! labelFont button and label text
!! textFont help and error dialog text
#if WIDTH < 1024
Dtlogin*labelFont: -dt-interface system-medium-r-normal-s*-*-*-*-*-*-*-*-*-*:
Dtlogin*textFont: -dt-interface user-medium-r-normal-s* -*-*-*-*-*-*-*-*-*:
Dtlogin*greeting.fontList: -dt-interface system-medium-r-normal-xl*-*-*-*-*-*-*-*-*-*:
#else
Dtlogin*labelFont: -dt-interface system-medium-r-normal-l*-*-*-*-*-*-*-*-*-*:
Dtlogin*textFont: -dt-interface user-medium-r-normal-l* -*-*-*-*-*-*-*-*-*:
Dtlogin*greeting.fontList: -dt-interface system-medium-r-normal-xxl*-*-*-*-*-*-*-*-*-*:
#endif
!!
!!#########################################################################
!! CURSOR
.....
.....
!!#########################################################################
!! GREETING
Dtlogin*greeting.foreground: black
Dtlogin*greeting.background: #a8a8a8
Dtlogin*greeting.labelString: Welcome to %LocalHost%
Dtlogin*greeting.persLabelString: Welcome %s
Dtlogin*greeting.alignment: ALIGNMENT_CENTER
!!#########################################################################
!! Size of Text Input Area
.....
.....
!!#########################################################################
!! MISC
.....
.....
!!#########################################################################
!! LANGUAGE MENU NAME MAPPINGS
.....
.....
!!########################################################################
!! Session MENU NAME MAPPINGS
!! Number of desktop's defined here for session menu
.....
.....
!!#########################################################################
!! CHOOSER
.....
.....
!!#########################################################################
!!
!! To disable options in dtgreet window, uncomment the appropriate
!! line below.
.....
.....
!!****************************************************************************
!! CUSTOMIZATION HINTS
!!
!! The login screen was designed to be easy to customize for a variety of
!! attributes. These include…
!!
!! 1. custom logo bitmap
!! 2. custom greeting message
!! 3. colors
!! 4. fonts
!!
!! Users may replace the default logo with a custom one of their choice.
!! Colors and fonts can be changed using the standard Motif resources for
!! the appropriate widget and/or class.
!!
!!****************************************************************************
3. 特定厂商X版本配置示例
3.1 Hewlett - Packard VUE配置
大多数特定厂商的X版本在配置方面有相似的方法,因为它们都基于X11R4。这里以Hewlett - Packard Visual User Interface (VUE)为例(实现平台为HP - UX 10.20)。
VUE的基本配置与CDE非常相似,甚至文件名也相同。VUE配置文件名为
Xconfig
,该文件对VUE进行了深入配置,几乎定义了所有VUE资源。配置文件位于
/usr/vue/config
目录,目录内容如下:
$ls /usr/vue/config
Xaccess Xconfig
Xconfig.orig Xerrors Xfailsafe
Xpid Xreset Xresources
Xservers Xsession
Xsession.test Xstartup
def−actions dialogs import
panels sys.font sys.res.lite sys.resources sys.ses.lite
sys.session sys.vueprofile sys.vuewmrc types
VUE在系统启动时通过
/etc/inittab
文件中的特殊“inittab条目”启动:
$ cat /etc/inittab | grep "vue"
vue:4:respawn:/ usr/vue/bin/vuerc # VUE invocation
启动的程序作为守护进程运行:
$ ps -ef |grep "vue" | grep -v "grep"
root 1441 10 Jan 5 ? 0:00 /usr/vue/bin/vuerc /usr/vue/bin/vuerc
3.2 VUE的Xconfig文件
VUE的
Xconfig
文件结构与CDE的配置文件非常相似,但内容有所不同。部分内容如下:
$ cat /usr/vue/config/Xconfig
########################################################################
###
### Xconfig
###
### Configuration file for the Login Manager
###
### @(#)Hewlett−Packard Visual User Environment, Version 3.0
### Copyright (c) Hewlett−Packard Company
###
### ______________________________
###
### This file contains behaviour resources for the HP VUE Login Manager.
### It also specifies the location of other configuration files used by
### the Login Manager.
###
### Appearance resources for the login screen are contained in the file
### specified by the "*resources" resource below.
###
### Most resources can be limited to a single display by including the
### display name in the resource. If the display name is not included, the
### resource will apply to all displays managed by the Login Manager. When
### specifying the display name, replace the ":" character in the name
### with an underscore "_". If the name is fully qualified, also replace
### dot "." characters with underscores.
###
### Example:
###
### Vuelogin*hpaaa_cv_hp_com_0*startup: /etc/vue/config/Xstartup.aa
###
### For more information see the man page, Vuelogin(1X).
###
########################################################################
Vuelogin.errorLogFile: /var/vue/Xerrors
Vuelogin.pidFile: /var/vue/Xpid
Vuelogin.accessFile: /etc/vue/config/Xaccess
Vuelogin.servers: /etc/vue/config/Xservers
Vuelogin*resources: /etc/vue/config/Xresources
Vuelogin*startup: /etc/vue/config/Xstartup
Vuelogin*session: /etc/vue/config/Xsession
Vuelogin*reset: /etc/vue/config/Xreset
Vuelogin*failsafeClient: /etc/vue/config/Xfailsafe
########################################################################
## Other well commented "configuration sections" follow
.....
.....
管理特定厂商的X版本与之前讨论的内容概念相同,配置规则、数据组织和配置文件都几乎相同,差异主要在于程序和配置文件的命名,这些名称也具有一定的可识别性。所有与X相关的管理技能都是完全通用的。
4. X11的访问控制与安全
4.1 XDMCP查询类型
X运行在网络环境中,这意味着客户端主机理论上可以被网络上的任何主机访问,有时这些访问可能带有恶意意图。潜在入侵者只需声明自己为X服务器即可尝试访问。因此,从管理角度来看,安全问题尤为重要。
XDMCP(X显示管理器控制协议)中定义了三种访问客户端主机的查询类型,这些查询源自远程X服务器(为便于理解,后续文本中我们将“远程X服务器”称为“X终端”),三种查询类型如下:
1.
直接查询
:远程X服务器直接向客户端主机发送查询请求。
2.
间接查询
:通过中间服务器转发查询请求到客户端主机。
3.
广播查询
:远程X服务器在网络中广播查询请求,客户端主机接收到广播后进行响应。
这三种查询类型的关系可以用以下mermaid流程图表示:
graph LR
classDef process fill:#E5F6FF,stroke:#73A6FF,stroke-width:2px;
A(远程X服务器):::process -->|直接查询| B(客户端主机):::process
A -->|间接查询| C(中间服务器):::process
C -->|转发| B
A -->|广播查询| D(网络广播):::process
D -->|接收响应| B
4.2 安全考虑与管理建议
由于X系统在网络环境中的开放性,管理员需要采取一系列措施来确保系统的安全性。以下是一些建议:
1.
访问控制
:通过配置访问控制文件(如CDE中的
Xaccess
文件),限制允许访问客户端主机的主机列表。
2.
加密通信
:使用加密协议(如SSH)来保护X会话的通信,防止数据在传输过程中被窃取或篡改。
3.
定期更新
:及时更新X系统和相关软件,以修复已知的安全漏洞。
4.
监控日志
:定期查看系统日志(如CDE中的
Dtlogin.errorLogFile
指定的日志文件),及时发现异常访问行为。
4.3 不同配置文件的安全作用
不同的配置文件在X系统的安全管理中发挥着不同的作用,以下是一些主要配置文件及其安全相关功能的总结:
| 文件名称 | 安全相关功能 |
| ---- | ---- |
| Xaccess | 定义允许访问客户端主机的主机列表,实现基本的访问控制。 |
| Xconfig | 通过配置各种资源和文件路径,确保系统按照安全策略运行。例如,指定错误日志文件和PID文件的位置,便于监控和管理。 |
| Xresources | 可以通过配置登录屏幕的外观和行为,隐藏敏感信息,防止信息泄露。 |
5. 总结与最佳实践
5.1 配置要点回顾
通过前面的介绍,我们了解了X系统的各种配置文件及其作用,包括基础配置文件(如
.xsession
、
Xsession
、
Xreset
)、CDE配置文件(如
Xconfig
、
Xservers
、
Xresources
)以及特定厂商的配置文件(如HP VUE的
Xconfig
)。这些配置文件相互协作,共同构建了一个完整的X系统环境。
5.2 安全管理最佳实践
为了确保X系统的安全性和稳定性,我们可以遵循以下最佳实践:
1.
备份配置文件
:在进行任何配置更改之前,先备份相关的配置文件,以便在出现问题时可以恢复到之前的状态。
2.
谨慎修改系统文件
:对于系统范围的配置文件(如
Xsession
),修改时要格外谨慎,最好在测试环境中进行测试后再应用到生产环境。
3.
遵循安全策略
:根据组织的安全要求,制定并遵循相应的安全策略,如访问控制策略、加密策略等。
4.
持续学习与更新
:X系统不断发展,新的安全漏洞和配置方法也会不断出现。管理员需要持续学习,及时更新系统和知识,以应对不断变化的安全挑战。
5.3 未来展望
随着技术的不断发展,X系统也在不断演进。未来,我们可以期待更加安全、易用的X系统配置和管理方式。例如,自动化配置工具的出现可以减少手动配置的工作量和错误率;更强大的安全机制可以更好地保护系统免受各种攻击。同时,随着云计算和容器技术的普及,X系统也可能会与这些技术进行更深入的融合,为用户提供更加灵活和高效的使用体验。
总之,深入了解X系统的配置和安全管理是管理员必备的技能之一。通过合理配置和有效管理,我们可以确保X系统在网络环境中安全、稳定地运行,为用户提供优质的服务。
超级会员免费看
1万+

被折叠的 条评论
为什么被折叠?



