Accessing SSH_AUTH_SOCK from another non-root user
There are two things you need to do:
- set the
SSH_AUTH_SOCK
variable so it points to the correct file - allow the other user to connect to the socket (using file system permissions)
Therefore, what you could do is:
As user1, allow user2 to connect to the socket (full access to the socket and permissions to enter the directory). I hope your /tmp
allows ACLs.
setfacl -m u:user2:rw $SSH_AUTH_SOCK
setfacl -m u:user2:x $(dirname $SSH_AUTH_SOCK)
Change to the other user, and export the variable correctly.
sudo -u user2 env SSH_AUTH_SOCK=$SSH_AUTH_SOCK ssh user3@machine2
If you want to open an interactive shell using sudo
, you would have to export the SSH_AUTH_SOCK
variable yourself after you get the shell.