Skip to content

Instantly share code, notes, and snippets.

@matfax
Last active July 21, 2025 13:16
Show Gist options
  • Save matfax/8853783a56aa886d7019d7b8024437ad to your computer and use it in GitHub Desktop.
Save matfax/8853783a56aa886d7019d7b8024437ad to your computer and use it in GitHub Desktop.
Sudo authentication with Windows 1Password CLI on Ubuntu WSL
# ....
alias op="op.exe"
eval "$(op completion zsh)"; compdef _op op.exe
alias sudo="sudo -A"
sudo apt update && sudo apt install jq # jq is only necessary for selecting the ID from op json output, which can as well be done manually
oppassid=$(op item get 'your 1Password item name/identity' --format json | jq -r '.id')
sudo tee -a /usr/local/bin/sudopwd <<EOF
#!/bin/bash
op.exe item get $oppassid --reveal --fields label=password
EOF
sudo chmod +x /usr/local/bin/sudopwd
cp ~/.zshrc ~/.zshrc.bak # backup zshrc, or bashrc
echo 'alias sudo="sudo -A"' >> ~/.zshrc # or bashrc
echo 'Path askpass /usr/local/bin/sudopwd' | sudo tee -a /etc/sudo.conf
# ....
Path askpass /usr/local/bin/sudopwd
#!/bin/bash
op.exe item get the_id_of_your_secret --fields label=password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment