I have set up my server to allow key/pair authentication by following instructions similar to what is found in this post.

As far as I can tell that is working correctly. If I do the following, for example, it works correctly:

ssh myusername@mydomain.com

It will NOT prompt me for a password. This is what I want to happen. However if I write a small bash script like this:

#!/bin/bash -x
ssh myusername@mydomain.com

and execute with:

sudo ./mytestscript.sh

...it will prompt me with:

myusername@mydomain.com's password:

What am I doing wrong? I need to be able to login from within my script without being prompted for a password!

| improve this question | | | | |

I'm guessing that the script works fine if you run it without sudo. If that is the case, than your problem is that ssh is now looking for the public key in root's home directory instead of yours. Add a -i option to your ssh command specifying the path to the key you've configured, or use root's public key instead.

If you're using ssh-agent to store a decrypted version of your key rather than using a passphrase-less key, you also need to edit /etc/sudoers and add env_keep+="SSH_AUTH_SOCK SVN_SSH to the Defaults so ssh can find your auth socket.

| improve this answer | | | | |
  • You are correct! The script does work without using sudo. I will try the -i option and let you know the result! Thanks! – Aaron Wright Apr 15 '10 at 5:49
  • Your solution worked perfectly! Thanks again! I would vote you up but I don't have the reputation yet. – Aaron Wright Apr 15 '10 at 6:53
  • Heh... You should be able to mark an answer as "accepted" even with low reputation points. Glad it worked! – Insyte Apr 15 '10 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.