2

I know its been asked so many times but i couldn't get answers for my problem. I am trying to ssh to system using config file. Config file is

Host qa
    HostName 10.218.70.345
    User user
    IdentityFile C:/Users/bean/.ssh/id_rsa.pub
    Port 22

When i run the below command

$ ssh -v qa
OpenSSH_8.0p1, OpenSSL 1.1.1c  28 May 2019
debug1: Reading configuration data /c/Users/bean/.ssh/config
debug1: /c/Users/bean/.ssh/config line 1: Applying options for qa1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.218.70.345 [10.218.70.345] port 22.
debug1: Connection established.
debug1: identity file C:/Users/bean/.ssh/id_rsa.pub type 0
debug1: identity file C:/Users/bean/.ssh/id_rsa.pub-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000002
debug1: Authenticating to 10.218.70.345:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256     SHA256:CWRMF3n1hQRu6ahabqm/0Ge1KOip6oe/xfJkOUDfRbQ
debug1: Host '10.218.70.345' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/bean/.ssh/known_hosts:10
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
debug1: Server accepts key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
Load key "C:/Users/bean/.ssh/id_rsa.pub": invalid format
debug1: Next authentication method: password
user@10.218.70.345's password:

Tried giving access to the files but none of them worked.

But the strange thing is when i do ssh user@<ip_address> it works perfectly. Can someone tell where and what is going wrong

Prateek Naik
  • 2,522
  • 4
  • 18
  • 38
  • 1
    `IdentityFile C:/Users/prateek.naik/.ssh/id_rsa.pub` https://stackoverflow.com/a/29948797/13317 – Kenster Sep 12 '19 at 20:18
  • Possible duplicate of [SSH Key: “Permissions 0644 for 'id\_rsa.pub' are too open.” on mac](https://stackoverflow.com/questions/29933918/ssh-key-permissions-0644-for-id-rsa-pub-are-too-open-on-mac) – Kenster Sep 12 '19 at 20:18
  • After going through all these links then only i posted this question. One link suggests to provide `chmod` and another one suggests to have `IdentityFile` line in `config` file. If you look at my file it already has that line and also gave required permissions. If i just do `ssh user@` am able to login to box – Prateek Naik Sep 13 '19 at 04:06

2 Answers2

4

You would need to use:

IdentityFile C:/Users/bean/.ssh/id_rsa

Not "id_rsa.pub" as in the question: your config file must mention the private key, not the public one.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Ben.Bean OK. I have rewritten the answer with the actual cause for your error. – VonC Sep 13 '19 at 08:24
  • The logs in the question tell you this `Load key "C:/Users/bean/.ssh/id_rsa.pub": invalid format`. You're using your public key whereas, like VonC said, you should use your private one. – Noufal Ibrahim Sep 13 '19 at 08:29
-1

Add PreferredAuthentications publickey at your config file. And no need to use .pub as file format

For Example:

Host github.com
   HostName github.com
   PreferredAuthentications publickey
   IdentityFile ~/.ssh/id_rsa
Fatema Tuz Zuhora
  • 3,088
  • 1
  • 21
  • 33
  • can you tell me where and do i need to remove/replace the line `IdentityFile C:/Users/bean/.ssh/id_rsa.pub` – Prateek Naik Sep 13 '19 at 08:01
  • can you please [go through the following link](https://stackoverflow.com/questions/56287059/how-to-set-up-an-ssh-config-file-for-beginners/56536275#56536275). Hopefully, you will find something helpful. – Fatema Tuz Zuhora Sep 13 '19 at 08:15