【发布时间】:2016-03-03 16:54:32
【问题描述】:
我有以下配置文件:
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
这些空格似乎是制表符。在 vim 中打开列表 (:set list) 显示:
#%PAM-1.0$
auth^I^Isufficient^Ipam_rootok.so$
# Uncomment the following line to implicitly trust users in the "wheel" group.$
#auth^I^Isufficient^Ipam_wheel.so trust use_uid$
# Uncomment the following line to require a user to be in the "wheel" group.$
#auth^I^Irequired^Ipam_wheel.so use_uid$
auth^I^Isubstack^Isystem-auth$
auth^I^Iinclude^I^Ipostlogin$
account^I^Isufficient^Ipam_succeed_if.so uid = 0 use_uid quiet$
account^I^Iinclude^I^Isystem-auth$
password^Iinclude^I^Isystem-auth$
session^I^Iinclude^I^Isystem-auth$
session^I^Iinclude^I^Ipostlogin$
session^I^Ioptional^Ipam_xauth.so$
我要匹配就行了:
#auth required pam_wheel.so use_uid
整行匹配不起作用。我不知道为什么......猜测它与空格标签有关:
grep "#auth required pam_wheel.so use_uid" /etc/pam.d/su
(返回不匹配)
所以,我认为值得尝试通过以下方式进行匹配:
grep "#auth\s+required\s+pam_wheel.so\s+use_uid" /etc/pam.d/su
我将这个正则表达式读作“#auth”,后跟至少一个或多个制表符/空格,然后是“必需”,然后是至少一个或多个制表符/空格,然后是“pam_wheel.so”等。 .
但是,这也不匹配。我不确定这里出了什么问题。我错过了什么?
【问题讨论】:
-
grep正则表达式不支持\s转义序列。如果您使用的是 GNU grep,请使用-P选项来使用 PCRE 正则表达式。 -
你也应该在 "pam_wheel.so" -> "pam_wheel\.so" 中转义句号