0

I use ssh-keygen to generate a pair of keys on Kali ~/.ssh folder.

Great. I also added the public key to ~/.ssh/authorized_keys. Permissions have been set to 600 for that file too.

Results are:

  • Putty: logged in as trunks@lanIP with ip_rsa.ppk - invalid format.
  • PowerShell telnet: ssh trunks@lanip -i path to private key file - invalid format.

I even converted to openSSH to no avail. What am I doing it wrong? I keep logging in to my regular login account such as username and password, that's not what I wanted. SIGH. Never had this problem before. Putty need to update their software. Seriously.

I checked the public key and it's one string long, proper format. I have no problems witn DD-WRT using putty telnet with public key string.

6
  • 2
    First, putty needs a specific format for its '.ppk' files. It looks something like: pastebin.com/EjQ5DA5R, containing private and public key in a fixed format. You may create such a file with puttygen, and then convert to openSSH format afterwards. I do not know anything about powerShell, unfortunately. Edit: Updated link.
    – gerhard d.
    Jun 23, 2022 at 6:25
  • 1
    Please edit your question to show the exact commands that you're running and the exact error messages that you're getting. Don't paraphrase the error messages.
    – Kenster
    Jun 23, 2022 at 11:25
  • Do I convert it to openSSH and save it as for both private and public key? Jun 23, 2022 at 14:43
  • @Kenster Kali doesn't have /etc/var/secure to look at the error messages for secure ssh connection. I looked, it isn't there. Jun 23, 2022 at 14:54
  • Now it's showing "server refuse our key" sigh.. lol. Again, no error message on /etc/var/secure Jun 23, 2022 at 14:56

2 Answers 2

1

ssh-keygen can generate files in three formats:

  • OpenSSH own format (RFC4716, the default),
  • PKCS8 and
  • PEM format.

You can distinguish them by the first line of the private key:

  • if it says "-----BEGIN OPENSSH PRIVATE KEY-----", it's RFC4716,
  • if it says "-----BEGIN RSA PRIVATE KEY-----", it is PEM,
  • and if it is just "-----BEGIN PRIVATE KEY-----" it is PKCS8.

In all cases, the public key looks the same. It is also able to convert freely between those formats.

What you use in PowerShell is OpenSSH. You can verify that by running ssh -V. It should work with keys in any of these formats out of the box.

To convert a file generated by the ssh-keygen into Putty's ppk format, use puttygen. Or, you may generate the key with puttygen and it is able to convert it into the OpenSSH format.

The public key contains three parts, "type key comment", of which the last is optional and can be changed freely. It can be used in the authorized_keys file to tag keys (e.g. to explain where the corresponding private key is or whose key it is). Other parts should be copied verbatim. Notice, that the public key always contained in a single line, and it should be appended as an individual line to the authorized_keys file.

If you are already able to ssh to the target host using any authentication mechanism, try ssh-copy-id target-host, which will create the .ssh/authorized_keys with correct privileges if it doesn't exist and add private key there, or it will append the key if file exists but the key is not in the file. The other way to build such a file is something like cat id_rsa.pub >> authorized_keys.

0
-1

I would ensure that the copy/pasted private key has the same file size as the original one. Text editors can add or ignore a line break at the end of the file, causing this issue.

4
  • Nikitia - that's what I did. I append the public key to authorized_keys and chmod it to 600. Sorry, I am learning :D. Thanks. Jun 23, 2022 at 15:37
  • The problem is I am logging into standard username/password mechanism, not the SSH mechanism. This is why I am very confused. Jun 23, 2022 at 15:49
  • Edited sshd_config to enable passwordless authentication using public key. No go. If PuttyGen is going to generate keys maybe they need to make PROPER FORMATTING! AND ELIMINATE WHITESPACE! This is messed up. Jun 23, 2022 at 17:30
  • Jonathan, please follow @Kenster 's advice, and edit your question. Include the exact command and the error message. Also specify, have you generated the pair of keys on the service or client-side.
    – kodcode
    Jun 23, 2022 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .