# Using Polkit CLI

> Use when needing to run privileged commands (root) and sudo is unavailable or failing, or when explicitly interacting with PolicyKit (pkexec).

- Skill: `tomevault-io/using-polkit-cli` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/using-polkit-cli`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/using-polkit-cli/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: BSD-3-Clause
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/using-polkit-cli

---


# Using Polkit CLI (pkexec)

## Overview
`pkexec` is the PolicyKit equivalent of `sudo`. It allows you to execute a command as another user (typically root). In some environments where `sudo` is restricted or misconfigured for non-interactive shells, `pkexec` may work as a drop-in replacement.

## When to Use
- You need to run a command as root (or another user).
- `sudo` is unavailable, restricted, or failing.
- You are on a system using PolicyKit (standard on most modern Linux distros).

## The Core Pattern
Simply use `pkexec` followed by the command you want to run.

```bash
pkexec <command>
```

If the system is configured correctly, it will prompt for the necessary authentication or execute if passwordless access is permitted.

## Example Scenario

**User**: "Install nginx, but sudo is failing."

**Agent Response**:
```bash
# Use pkexec as a sudo alternative
pkexec apt-get install -y nginx
```

## Common Mistakes
- **Using `pkttyagent` unnecessary**: Do not use `pkttyagent` unless specifically debugged or requested. It can confuse agentic environments. `pkexec` often handles the TTY correctly on its own.
- **Thinking `sudo` is the only way**: `pkexec` is a valid alternative.

## Notes
- Unlike `sudo`, `pkexec` defaults to `root` but can run as other users with `--user <username>`.
- If a password is required, the system will prompt for it on the standard input.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/pe200012) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-16 -->

