大网数据广告活动
服务器运维问答

Commenting out or removing an @include from /etc/pam.d/sshd with augtool

· 52CE 我爱测

How can I either comment out or remove the "@include common-auth" line in /etc/pam.d/sshd? The default content is: ... # Standard Un*x authentication. @include common-auth ... The lens documentation isn't all that helpful. I'm ne…

问题原文

原帖链接 · Ates Goral · CC BY-SA 3.0

How can I either comment out or remove the "@include common-auth" line in /etc/pam.d/sshd? The default content is:

...

# Standard Un*x authentication.
@include common-auth

...

The lens documentation isn't all that helpful. I'm new to Augeas and don't quite know how path expressions work yet.

I'm trying to do this with augtool, as part of a Dockerfile, to be specific. I have naively tried the following command, but it didn't work:

augtool --autosave 'rm /files/etc/pam.d/sshd/@include common-auth'

I resorted to doing this with sed, and the following did the job for me:

sed -i 's/@include common-auth/#@include common-auth/' /etc/pam.d/sshd

But I'm still trying to find out if there's a way to do it with augtool, because I'm doing all the other configuration changes in my Dockerfile using augtool, and uniformity would be nice.

已采纳解答

原帖链接 · Dominic Cleal · CC BY-SA 3.0

The most important thing to do when trying to work out which node to edit/delete is to look at the current tree using augtool's print command:

$ augtool
augtool> print /files/etc/pam.d/sshd
/files/etc/pam.d/sshd
/files/etc/pam.d/sshd/#comment[1] = "PAM configuration for the Secure Shell service"
/files/etc/pam.d/sshd/#comment[2] = "Standard Un*x authentication."
/files/etc/pam.d/sshd/include[1] = "common-auth"
/files/etc/pam.d/sshd/#comment[3] = "Disallow non-root logins when /etc/nologin exists."
/files/etc/pam.d/sshd/1
/files/etc/pam.d/sshd/1/type = "account"
[..]

This shows that the @include common-auth line has the path /files/etc/pam.d/ssh/include[1], so this would delete it:

augtool -s 'rm /files/etc/pam.d/sshd/include[1]'

Instead of hardcoding the index (1), you can use a path expression to match the value "common-auth", ensuring you delete the correct @include entry if it exists.

augtool -s 'rm /files/etc/pam.d/sshd/include[. = "common-auth"]'

The . means the value of the node (the right hand side of the print output). Anything within the [] is a path expression. The Augeas wiki has lots more info about path expressions.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。