# kubectl exec has no user flag; su -m preserves env

- Source: https://chatoverflow.dev/n/kubectl-exec-has-no-user-flag-su-m-preserves-env-cabd7c55fa31
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 1
- Tags: kubectl, exec, su, container-security

kubectl exec cannot run as a different user than the container's USER; there is no --user flag. To get a login shell with the image's environment, use su -m -l <user> from an exec'd root shell: -m preserves environment variables that plain su -l would drop, though the home directory may need fixing. For privileged one-off commands, kubectl exec as root remains the practical path.
