Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't work from script #11

Open
532910 opened this issue May 31, 2018 · 3 comments
Open

doesn't work from script #11

532910 opened this issue May 31, 2018 · 3 comments

Comments

@532910
Copy link

532910 commented May 31, 2018

% cat /tmp/test.zsh
#!/bin/zsh

echo $SSH_AUTH_SOCK
sudo echo OK

% /tmp/test.zsh    
/home/sergio/.gnupg/S.gpg-agent.ssh
[sudo] password for sergio: 
/var/log/auth.log:

Beginning pam_ssh_agent_auth for user sergio
Attempting authentication: `sergio' as `sergio' using /etc/ssh/sudo_authorized_keys
No ssh-agent could be contacted
Failed Authentication: `sergio' as `sergio' using /etc/ssh/sudo_authorized_keys

Directly from console all works fine:

% sudo echo OK
OK

/var/log/auth.log:
Beginning pam_ssh_agent_auth for user sergio
Attempting authentication: `sergio' as `sergio' using /etc/ssh/sudo_authorized_keys
Contacted ssh-agent of user sergio (1000)
trying public key file /etc/ssh/sudo_authorized_keys
auth_secure_filename: checking for uid: 0
secure_filename: checking '/etc/ssh'
secure_filename: checking '/etc'
secure_filename: checking '/'
matching key found: file/command /etc/ssh/sudo_authorized_keys, line 1
Found matching ED25519 key: ID
ssh_ed25519_verify: signature correct
Authenticated: `sergio' as `sergio' using /etc/ssh/sudo_authorized_keys
@gnanet
Copy link

gnanet commented Sep 25, 2018

Did a quick search on the subject, and i suggest to read this:
understanding ssh-agent and ssh-add

My assumption is, that your shell script is spawning an ssh-agent, an this way you have the $SSH_AUTH_SOCK set, but that variable may point to an instance of ssh-agent which does not list your keys (it is empty maybe)
So the best way would be to use this project to set up the agent, and the socket variable properly:
ssh-find-agent

@gnanet
Copy link

gnanet commented Oct 11, 2018

I have an extra info, at least for sudo inside a screen session, it is strongly advised for sudo <= 1.8.5 to add Defaults env_keep += "SSH_AUTH_SOCK" and you can always look for multiple ssh-agents, and try to keep only one

@Wilm0r
Copy link

Wilm0r commented Dec 26, 2019

Interestingly I needed to add that to my sudo config even with Debian Buster's current version of sudo, 1.8.27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants