0

I've generated a keypair for my school project running on a raspberry pi (running raspbian). When I run

ssh -f -N -R 54321:localhost:22 mylogin@host

in the commandline I get no problems. The tunnel is set up without me having to enter my password. However when I try to run the exact same code from a shell script it prompts me for my password. Anyone know my error?

Michiel Ariens
  • 288
  • 4
  • 12
  • can you share the script or how you are running the script? – neo Nov 05 '13 at 16:12
  • Have a look at http://stackoverflow.com/questions/15657821/something-goes-wrong-with-the-ssh-while-setting-up-hadoop, Hope it solves your issue. – neo Nov 05 '13 at 16:29

1 Answers1

1

In most Linux distributions, an instance of ssh-agent is started when you log in. This is a background process that holds onto decrypted copies of your SSH keys; the ssh command will attempt to go through ssh-agent to gain access to the keys in order to do public-key authentication. The point of ssh-agent is that you should only need to enter your password for an SSH key once during a login session. (On some distros you don't even need to enter this - your keys are automatically decrypted when you log in.)

I'm guessing you're trying to run your script from cron, or from some other server process (like a web server or CGI script)? If so, it won't have the necessary environment variables set up for the ssh command to talk to ssh-agent - so it will prompt for a password (and thus fail if it's not being run within a terminal).

You can get around this by storing an unencrypted copy of your SSH key (so you won't need ssh-agent to decrypt it), but as this is a major security no-no this is generally only done for SSH keys that allow access to locked-down, minimally-privileged accounts.

pobrelkey
  • 5,853
  • 20
  • 29
  • The keys are stored decrypted and security is no issue as it's in a classroom environment with no outside internet access. I'm launching the script from rc.local calling a python script to run the commands. When the script is called automatically i get "host key verification failed". When I manually run the script a second later everything is fine. I've found a workaround by launching xsession and running a background application but this isn't a very good solution in my opinion. – Michiel Ariens Nov 16 '13 at 17:05