1

When I login to server with a key

ssh -i /home/me/.ssh/id_rsa server

everything goes without glitch. The key is authorized on the server. However if I try to do same from a shell script, I get a password request. Same happens when I try to scp using the keyfile:

scp -i /home/me/.ssh/id_rsa file server:

I have also created ~/.ssh/config for the host:

Host server
    hostname server
    IdentityFile /home/me/.ssh/id_rsa

When I try to SSH in just with ssh server I also get a password request. The keyfile, ssh config and server's authorized_keys have privileges set to 600.

What can I do to resolve this?

EDIT

Same also happens with sshfs.

sshfs -o IdentityFile=/home/me/.ssh/id_rsa server:/directory mountpoint

from cli works fine. When it's in a shell script, I get a password request.

Peregrino69
  • 149
  • 6
  • Under what user is the script running // How are you running the shell script? – c4urself Dec 14 '14 at 22:41
  • I've tried two ways: starting the script just from the shell, and running it from .bashrc when I login. So I'd assume with my credentials? – Peregrino69 Dec 14 '14 at 23:23
  • It would be easier to help if you provided longer examples. Just copy the entire session. In the second example you're missing for example the `.ssh` directory found in the first example. You should try specifying absolute paths everywhere for test. Do the logs on the remote side give away something special? – Marki Dec 15 '14 at 02:16
  • Thanks for pointing out about the missing dir, I fixed in the question. I actually was using absolute paths. I re-generated my ssh keys a couple of times with no luck, and suddenly for some reason both ssh with script and using the config file work. With sshfs you pointed me to right direction. I _thought_ ~/.ssh/id_rsa was full enough path with sshfs when I put ~/.ssh/id_rsa - but apparently not. Using real full path /home/me/.ssh/id_rsa with sshfs works. I would've thought that when I'm at ~/, sshfs .ssh/id_rsa would be enough but apparently not. – Peregrino69 Dec 15 '14 at 03:08
  • I was just going to continue that scp appears to be broken since even scp file user@server didn't work... but tested one more time and now it does. Go figure :P Maybe it has something to do with the server owner fumbling the user accounts so that he had to re-create them this evening. Anyway thank you for helping me straighten this out :) – Peregrino69 Dec 15 '14 at 03:13

1 Answers1

0

This was probably due to .ssh directory or user's home directory not having the correct permissions. Re-creating the users likely fixed that.

Gunstick
  • 101
  • 1