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,554