Skip to content

Commit 6ad44c3

Browse files
committed
Fix enabling Touch ID for sudo on macOS 26+. Issue 12753
1 parent d78ab0c commit 6ad44c3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sources/iTermTouchIDHelper.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class iTermTouchIDHelper: NSObject {
5252
return true
5353
}
5454

55-
// Create file from template if needed, make it writable, enable Touch ID, restore permissions.
56-
// We use sed to uncomment the existing line (from template), and fall back to appending if
57-
// the line doesn't exist. chmod is needed because sudo_local is read-only by default.
55+
// Build the modified file in /tmp, then cp it into place. On macOS 26+, in-place writes
56+
// to /etc/pam.d/ (sed -i, shell redirects) fail with "Operation not permitted" even as
57+
// root, but cp still works.
5858
let templatePath = "/etc/pam.d/sudo_local.template"
59-
let shellCommand = "test -f \(sudoLocalPath) || cp \(templatePath) \(sudoLocalPath); chmod u+w \(sudoLocalPath); sed -i '' 's/^#auth.*pam_tid.so/\(pamTidLine)/' \(sudoLocalPath); grep -q '^auth.*pam_tid.so' \(sudoLocalPath) || echo '\(pamTidLine)' >> \(sudoLocalPath); chmod u-w \(sudoLocalPath)"
59+
let shellCommand = "T=$(mktemp) && { SRC=\(sudoLocalPath); test -f $SRC || SRC=\(templatePath); sed 's/^#auth.*pam_tid.so/\(pamTidLine)/' $SRC > $T && { grep -q '^auth.*pam_tid.so' $T || echo '\(pamTidLine)' >> $T; } && cp -f $T \(sudoLocalPath); R=$?; rm -f $T; exit $R; }"
6060

6161
let code = """
6262
do shell script "\(shellCommand)" with prompt "iTerm2 wants to enable Touch ID for sudo authentication." with administrator privileges

0 commit comments

Comments
 (0)