1

id_rsa and id_rsa.pub are located in K:\Batch\mySSH, with script K:\Batch\mySSH\runme.cmd being called from Excel (via VBA), containing the following:

pushd %~dp0
  set home=%CD:~0,2%\Batch\mySSH
  %home%\ssh -v -o LogLevel=Verbose user@11.111.111.11 "do something"
popd
  • runme.cmd output:
    OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2
    

    debug1: Connecting to 11.111.111.11 [11.111.111.11] port 22. debug1: Connection established. debug1: identity file C:\Users\johnDoe/.ssh/id_rsa type -1 ... debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory debug1: Will attempt key: C:\Users\johnDoe/.ssh/id_rsa ... debug1: Next authentication method: publickey debug1: Trying private key: C:\Users\johnDoe/.ssh/id_rsa

How do I ensure it looks for K:\Batch\mySSH\.ssh\id_rsa, instead of targeting C:\Users\johnDoe\.ssh?

JW0914
  • 7,865
user1224005
  • 11
  • 1
  • 3

1 Answers1

0

Ensure the -i parameter is used to specify your identity file; for instance change:

  • From:
    %home%\ssh -v -o LogLevel=Verbose user@11.111.111.11 "do something"
    
    To:
    %home%\ssh -v -o LogLevel=Verbose user@11.111.111.11 -i id_rsa "do something"
    
JW0914
  • 7,865
paddywan
  • 342
  • That doesn't work. It still looks for the file id_rsa in the folder C:\Users\johnDoe.ssh\ . However, this file is located in K:\Batch\mySSH.ssh\ – user1224005 Sep 29 '20 at 09:38
  • Try and use the absolute path to your identity file, you might need to escape spaces with \ if your path contains any. Hopefully this should fix your issue: -i K:\Batch\mySSH\.ssh\id_rsa.

    Alternatively, consider storing your identity files inside of your user directory, inside of .ssh. This would be better practice than leaving your identity outside of the user protected directory structure.

    – paddywan Sep 29 '20 at 09:42
  • I know that if I store the file in the user folder all works fine. I have tested that already. When using the option -i %home%.ssh\id_rsa , I'm getting the issue: Permissions for 'K:\Batch\mySSH\.ssh\id_rsa' are too open. – user1224005 Sep 29 '20 at 09:51
  • 1
    So the answer works. For the answer to your new problem, see https://superuser.com/q/1296024/213663 – Martin Prikryl Sep 29 '20 at 09:55