That's what hands look like, right?

Vibe Coding – sudo read this

So, I am pretty lazy when it comes to typing out long commands and constantly typing in my password on my Mac.  I worked with my coding coach (ChatGPT – and by coach I mean I just have it spit out the code).  I had it write this, if you are using iTerm2, and you should, it will give you a TouchID prompt IF you have a device with a TouchID sensor connected, or are using your MacBook keyboard itself with TouchID, otherwise it will just give a password prompt, like an animal.  It backs up all the files it touches, because I don’t trust ChatGPT that much.  If it borks you, I’m sorry, so make a backup of your machine first and I’ll buy you an adult beverage when next we see each other.

To create the we are going to: nano install_touchid_sudo.sh and then add:

#!/bin/zsh
# Install Touch ID for sudo in iTerm2 only when a Touch ID Magic Keyboard is connected.
# Backs up every file it touches with .bak.<timestamp> and records a manifest for clean backout.

set -euo pipefail

TS="$(date +%Y%m%d-%H%M%S)"
INSTALL_DIR="$HOME/.local/share/touchid-sudo-iterm2"
MANIFEST="$INSTALL_DIR/manifest.$TS"
PAM_SUDO="/etc/pam.d/sudo"
BIN_DIR="$HOME/bin"
SUDO_WRAPPER="$BIN_DIR/sudo"
ZSHRC="$HOME/.zshrc"

mkdir -p "$INSTALL_DIR"
: > "$MANIFEST"

note() { printf '%s\n' "$*"; }
record() { printf '%s\t%s\n' "$1" "$2" >> "$MANIFEST"; }  # type<TAB>path

# 1) Backup and ensure pam_tid.so is present in /etc/pam.d/sudo
note "Backing up and enabling Touch ID in $PAM_SUDO..."
sudo cp "$PAM_SUDO" "${PAM_SUDO}.bak.${TS}"
record "backup" "${PAM_SUDO}.bak.${TS}"

if ! grep -q 'pam_tid\.so' "$PAM_SUDO"; then
  tmp="$(mktemp)"
  # Insert pam_tid.so as the first non-comment line
  awk 'BEGIN{ins=0}
       /^#/ && ins==0{print; next}
       ins==0{print "auth       sufficient     pam_tid.so"; ins=1}
       {print}
       END{if(ins==0) print "auth       sufficient     pam_tid.so"}' \
       "$PAM_SUDO" > "$tmp"
  sudo cp "$tmp" "$PAM_SUDO"
  rm -f "$tmp"
  record "modified" "$PAM_SUDO"
else
  note "pam_tid.so already present; leaving $PAM_SUDO content unchanged (backup still created)."
fi

# 2) Create ~/bin and install sudo wrapper (backup any existing one)
note "Installing conditional sudo wrapper at $SUDO_WRAPPER..."
mkdir -p "$BIN_DIR"

if [[ -f "$SUDO_WRAPPER" ]]; then
  cp "$SUDO_WRAPPER" "${SUDO_WRAPPER}.bak.${TS}"
  record "backup" "${SUDO_WRAPPER}.bak.${TS}"
fi

cat > "$SUDO_WRAPPER" <<'ZWRAP'
#!/bin/zsh
# iTerm2-scoped sudo wrapper that prefers Touch ID only when a Touch ID Magic Keyboard is connected.

set -euo pipefail

is_iterm2() {
  [[ "${TERM_PROGRAM:-}" == "iTerm.app" ]]
}

has_touchid_keyboard() {
  # Bluetooth: look for Magic Keyboard with Touch ID entries that are connected
  if system_profiler SPBluetoothDataType 2>/dev/null | \
       awk 'BEGIN{IGNORECASE=1}
            /Magic Keyboard with Touch ID( and Numeric Keypad)?/ {seen=1}
            /Connected: Yes/ && seen {connected=1}
            /^$/{ if(connected){print "YES"; exit} seen=connected=0 }' | grep -q YES; then
    return 0
  fi
  # USB: wired usage
  if system_profiler SPUSBDataType 2>/dev/null | \
       grep -Ei 'Magic Keyboard with Touch ID( and Numeric Keypad)?' >/dev/null; then
    return 0
  fi
  return 1
}

if is_iterm2 && has_touchid_keyboard; then
  exec /usr/bin/sudo "$@"
else
  exec /usr/bin/sudo "$@"
fi
ZWRAP

chmod +x "$SUDO_WRAPPER"
record "created" "$SUDO_WRAPPER"

# 3) Ensure ~/bin is in PATH via ~/.zshrc (backup before edit)
ensure_path_line='export PATH="$HOME/bin:$PATH"'
if ! print -r -- "$PATH" | tr ':' '\n' | grep -qx "$HOME/bin"; then
  note "Ensuring $HOME/bin precedes PATH in $ZSHRC..."
  if [[ -f "$ZSHRC" ]]; then
    cp "$ZSHRC" "${ZSHRC}.bak.${TS}"
    record "backup" "${ZSHRC}.bak.${TS}"
  else
    # Touch to create, then back it up empty for symmetry
    : > "$ZSHRC"
    cp "$ZSHRC" "${ZSHRC}.bak.${TS}"
    record "backup" "${ZSHRC}.bak.${TS}"
  fi
  # Only append if not already present
  if ! grep -Fxq "$ensure_path_line" "$ZSHRC"; then
    printf '\n%s\n' "$ensure_path_line" >> "$ZSHRC"
    record "modified" "$ZSHRC"
  fi
else
  note "~/bin already on PATH in current shell; no edit to $ZSHRC."
fi

# 4) Save a copy of the wrapper and metadata for reference
cp "$SUDO_WRAPPER" "$INSTALL_DIR/sudo.wrapper.$TS"
record "created" "$INSTALL_DIR/sudo.wrapper.$TS"
note "Install complete.
Manifest: $MANIFEST

Open a new iTerm2 session or 'source ~/.zshrc' to pick up PATH changes.
Behavior:
- In iTerm2 with a Touch ID Magic Keyboard connected: sudo will allow Touch ID.
- Otherwise: sudo falls back to password."

Now hit control-x to exit and y to save

 The rollback!

Create the file:

nano uninstall_touchid_sudo.sh

and add this:

#!/bin/zsh
# Back out the most recent install by restoring backups from the newest manifest.
# You can pass a specific manifest path as $1 to target that install.

set -euo pipefail

INSTALL_DIR="$HOME/.local/share/touchid-sudo-iterm2"
MANIFEST="${1:-}"

if [[ -z "$MANIFEST" ]]; then
  MANIFEST="$(ls -1t "$INSTALL_DIR"/manifest.* 2>/dev/null | head -n1 || true)"
fi

if [[ -z "$MANIFEST" || ! -f "$MANIFEST" ]]; then
  printf 'No manifest found. Nothing to do.\n' >&2
  exit 1
fi

printf 'Using manifest: %s\n' "$MANIFEST"

restore_file() {
  local backup="$1"
  # Original path is the backup path without the trailing ".bak.<timestamp>"
  local orig="${backup%\.bak.*}"
  if [[ -f "$backup" ]]; then
    # If restoring /etc/pam.d/*, use sudo
    if [[ "$orig" == /etc/pam.d/* ]]; then
      sudo cp "$backup" "$orig"
      printf 'Restored (sudo): %s -> %s\n' "$backup" "$orig"
    else
      cp "$backup" "$orig"
      printf 'Restored: %s -> %s\n' "$backup" "$orig"
    fi
  else
    printf 'Backup missing, skipping: %s\n' "$backup" >&2
  fi
}

# Read manifest lines: "<type>\t<path>"
# We restore backups and then optionally remove created files saved under INSTALL_DIR.
while IFS=$'\t' read -r typ path; do
  case "$typ" in
    backup)
      restore_file "$path"
      ;;
    created)
      # Only delete created artifacts under our install dir; leave ~/bin/sudo in place
      # unless there is also a backup we restored above.
      if [[ "$path" == "$INSTALL_DIR/"* ]]; then
        rm -f "$path" && printf 'Removed created artifact: %s\n' "$path"
      fi
      ;;
    modified)
      # Nothing to do here; restoring from backups handles this.
      :
      ;;
    *)
      :
      ;;
  esac
done < "$MANIFEST"

# If we restored a backup of ~/bin/sudo, that copy is now back in place.
# If we did NOT restore one but want to remove our wrapper, uncomment the next block:
# if [[ -f "$HOME/bin/sudo" ]]; then
#   rm -f "$HOME/bin/sudo"
#   printf 'Removed wrapper at %s\n' "$HOME/bin/sudo"
# fi

printf 'Backout complete.\n'

Now hit control-x to exit and y to save

Now to execute it!

First we make them executable:

chmod +x install_touchid_sudo.sh uninstall_touchid_sudo.sh
./install_touchid_sudo.sh

Now to load it into our zsh open a new iTerm2 tab or run:

source ~/.zshrc

Then we will test:

sudo -v && echo "sudo cache primed; next sudo should prompt Touch ID if eligible." && sleep 2 && sudo true

If you want to kill it with fire:

./uninstall_touchid_sudo.sh

Lemme know how it goes if you trust me trusting ChatGPT enough to try it!

On my Github:
https://github.com/bionicrocky

Share:

7 thoughts on “Vibe Coding – sudo read this”

  1. [b][url=https://momspace.ru/articles/vybirayem-podushku-dlya-beremennykh-sovety-formy-napolniteli/]ортопедическая подушка для беременных[/url][/b]

    Может быть полезным: https://momspace.ru/articles/kak-pravilno-delat-massazh-grudnichku-polnoye-rukovodstvo-dlya-roditeley/ или [url=https://momspace.ru/39-nedelya-beremennosti/]срок беременности 39 недель[/url]

    [b][url=https://momspace.ru/32-nedelya-beremennosti/]32 неделя беременности сколько месяцев[/url][/b]

  2. ?Estas buscando un buen casino online con licencia espanola para jugar con dinero real? Como muchos jugadores en Madrid, estuve buscando una plataforma fiable hasta que encontre [url=casinos-dinero-real.mystrikingly.com]https://casinos-dinero-real.mystrikingly.com/[/url].
    Me tope con una lista confiable de casinos online con dinero real donde puedes jugar sin riesgos. Lo mas importante para mi fue que los operadores estan regulados por la DGOJ. Asi no tienes que preocuparte por fraudes. Ademas, el acceso movil esta optimizado. Funciona igual desde casa o fuera y la experiencia fue fluida.
    ?Bonos? ?Claro que si! Las plataformas recomendadas ofrecen bonificaciones increibles para que empieces con ventaja. ?Quieres jugar tragamonedas? La oferta es variada. Desde poker online en Espana hasta ruleta europea, todo esta ahi.
    El retiro de ganancias es rapido. Yo probe PayPal y fue instantaneo. Eso habla bien del sitio. Si estas en Espana, te recomiendo esta plataforma. Veras sitios seguros para ganar dinero en 2025.
    Jugar con responsabilidad es fundamental. Y hacerlo en un casino legal y seguro es el primer paso.
    No pierdas mas tiempo, entra a ver las opciones.

  3. Всем привет!
    Меня зовут Горислав и я обожаю смотреть онлайн мультсериал Южный Парк на сайте https://southpark-online.info
    Там много интересных серий, которые Вам понравятся.
    Присоединяйтесь!

  4. تعتبر 888starz منصة معروفة في صناعة الألعاب الإلكترونية. يوفر الموقع مجموعة كبيرة من خيارات الألعاب التي تلبي احتياجات جميع اللاعبين. تشمل الألعاب المتوفرة الرهانات الرياضية وألعاب الكازينو.

    تتمتع 888starz بواجهة مستخدم سهلة الاستخدام. يستطيع اللاعبون التصفح بين الأقسام بكل سلاسة. يساهم في جعل تجربة اللعب أكثر جاذبية.

    يستطيع المستخدمون الاستفادة من مجموعة متنوعة من المكافآت لجذب اللاعبين الجدد. يتضمن ذلك مكافآت للترحيب وعروض دورية. تعتبر هذه العروض حافزًا جيدًا لزيادة عدد اللاعبين.

    الأمان هو أحد أولويات 888starz. توظف 888starz أحدث التقنيات لحماية المعلومات الشخصية للمستخدمين. هذا يضمن تجربة لعب آمنة.

    الموقع الرسمي 888starz [url=http://www.888starz-egypt-eg.com]https://888starz-egypt-eg.com/[/url]

  5. Fani gier hazardowych w stolicy często poszukują miejsca, które łączy luksus z profesjonalną obsługą. Odpowiedzią na te potrzeby jest kasyno Marriott Warszawa. To eleganckie casino Poland proponuje swoim gościom unikalną scenerię i duży wybór automatów. Jeśli interesuje Cię kasyno w Warszawie, to miejsce w hotelu Marriott jest jedną z najlepszych propozycji. Dla wielu osób Marriott casino to synonim premium rozrywki. Niezależnie od tego, czy sprawdzasz kasyno Marriott, czy analizujesz ofertę casinos Poland, ta propozycja powinna zostać rozważona. Wielu użytkowników wpisuje do wyszukiwarki takich jak kasyno warszawa marriott lub marriott kasyno warszawa, aby odnaleźć to miejsce. Dla osób, które popełniają błąd literowy, wpisując kasyno mariot lub kasyno mariott, cel pozostaje ten sam – odnaleźć najlepszą grę. Porównując różne casinos Poland Katowice również mają swoją ofertę, jednak warszawski Marriott jest w czołówce. To doskonałe miejsce, aby grać w ulubione tytuły w eleganckim otoczeniu. Właśnie tutaj spotyka się klasa z emocjami. Można również pobrać specjalną aplikację, aby być na bieżąco z nowościami.

    [url=https://www.mixcloud.com/DevogiIraka/]https://www.mixcloud.com/DevogiIraka/[/url]

Comments are closed.