# Missing sudo password when using agent-based authentication for sudo

**URL:** <https://forum.ansible.com/t/missing-sudo-password-when-using-agent-based-authentication-for-sudo/8092>\
**Category:** Get Help\
**Created:** [August 26, 2024, 2:41pm UTC](https://forum.ansible.com/t/missing-sudo-password-when-using-agent-based-authentication-for-sudo/8092 "2024-08-26T14:41:27Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [August 27, 2024, 2:56pm UTC](https://forum.ansible.com/t/missing-sudo-password-when-using-agent-based-authentication-for-sudo/8092/6 "2024-08-27T14:56:14Z")

</div>

This is more of a sudo problem than an Ansible one.

When you ssh to a server, you create an interactive tty session with that remote host. When you run Ansible against your inventory, Ansible creates non-interactive tty sessions with the remote hosts.

Sudo has special rules for environment variables, when they are preserved, and when they are not. If you become root, should root use the non-root user’s ENV or load its own? Should it reset the ENV and load defaults? It has rules defined for various scenarios, but has arguments to work around those when exceptions arrise.

In your case, your SSH\_AUTH\_SOCK environment variable is preserved in your interactive session, but not in Ansible’s non-interactive session. Passing `become_flags=--preserve-env=SSH_AUTH_SOCK` to `become_method=sudo` then instructs sudo that it needs to preserve this ENV for the session, when it normally wouldn’t by default.

---

_[View the full topic](https://forum.ansible.com/t/missing-sudo-password-when-using-agent-based-authentication-for-sudo/8092)._
