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 [email protected]

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 [email protected]

and execute with:

sudo ./mytestscript.sh

...it will prompt me with:

[email protected]'s password:

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

1 Answer 1

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.

3
  • You are correct! The script does work without using sudo. I will try the -i option and let you know the result! Thanks! Apr 15, 2010 at 5:49
  • Your solution worked perfectly! Thanks again! I would vote you up but I don't have the reputation yet. Apr 15, 2010 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, 2010 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .