Linux: Use ssh agent forwarding while sudo to another user

Hi,

if you are logged on as a user1 and switch to another user2 with sudo the ssh agent from user1 cannot be used because the “switched” user2 does nothing know about the ssh-agent respectively the agent socket.

The path to the agent socket is stored in the SSH_AUTH_SOCK environment variable. So you have to keep/forward this variable to the switched user. This can be done by adding


Defaults env_keep+=SSH_AUTH_SOCK

to /etc/sudoers

Michael

Leave a Reply Cancel reply