2

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!

A.C. Wright
  • 123
  • 3

1 Answers1

6

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.

Insyte
  • 9,394
  • 3
  • 28
  • 45
  • You are correct! The script does work without using sudo. I will try the -i option and let you know the result! Thanks! – A.C. Wright Apr 15 '10 at 05:49
  • Your solution worked perfectly! Thanks again! I would vote you up but I don't have the reputation yet. – A.C. Wright Apr 15 '10 at 06: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