Invalid key error when loading SSH2 RSA sFTP public key

Problem:
One of our trading partner was unable to load our SSH2 RSA based sFTP public key. The partner was getting invalid key error when trying to import our public key in its sFTP server (in order to enable key based authentication)

Scenario Details:
We were trying to implement sFTP with a trading partner where we will connect to that partner’s sFTP as a client and by using key-based authentication.

We provided our sFTP public key to that partner and requested partner to upload that public key in its system to enable key-based authentication for sFTP connectivity.

The partner informed us that he is unable to upload our public key in its system and is getting invalid key error while attempting to upload key.

Resolution:
We were able to fix this issue by manually modifying our SSH2 RSA public key contents as following:

1.    Open SSH2 RSA public key in notepad or textpad
2.    Remove very first line (—- BEGIN SSH2 PUBLIC KEY —-)
3.    Remove very last line (—- END SSH2 PUBLIC KEY —-)
4.    Copy the part of the comments between the double quotes and paste it after the last character of the last line of public key (make sure there is a space between last char of last line and the comments that you just pasted)
5.    Now remove comments line (e.g. comment: “rsa-key-2014”)  from top of the public key
6.    Remove all new line chars from the end of each row such that whole key data comes in one/single row or line
7.    Now add word “ssh-rsa” (immediately followed by one space) to the start of row (i.e. start of the single row which contains whole of public key data/contents)
8.    Save the file

When we sent modified public key to our trading partner, this time it loaded successfully in it system.

Leave a comment