Report this

What is the reason for this report?

API add new ssh public key "ssh-rsa xxx+yyy+zzz me@me" becomes "ssh-rsa xxx yyy zzz me@me"

Posted on April 5, 2014

Hi. I’m using Ruby and DO API to create my public ssh key like this

RestClient.get URI.encode(“https://api.digitalocean.com/ssh_keys/new/?name=[ssh_key_name]&ssh_pub_key=[ssh_public_key]&client_id=[client_id]&api_key=[api_key]”))

The key is something like this “ssh-rsa xxx+yyy+zzz me@me” then after the call done, the key will be stored like this “ssh-rsa xxx yyy zzz me@me”. The “+” was replaced by space. So I have to use web interface to edit the key.

How could I do this correctly? Thank you.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

URI.encode doesn’t seem to be encoding the SSH string properly, it should be escaping the plus character. You should use CGI.escape instead, but keep in mind it should only be used on the ssh key itself otherwise it would escape the whole string rendering it unusable. There are a few gems that will escape the whole URI correctly. One of them being <a href=“http://rubydoc.info/gems/addressable/2.2.4/Addressable/URI#encode-class_method”>http://rubydoc.info/gems/addressable/2.2.4/Addressable/URI#encode-class_method</a> <br> <br>The following links might also help: <br> <br><ul><li><a href=“http://stackoverflow.com/questions/2824126/whats-the-difference-between-uri-escape-and-cgi-escape”>http://stackoverflow.com/questions/2824126/whats-the-difference-between-uri-escape-and-cgi-escape</a></li><li><a href=“http://ruby-doc.org/stdlib-1.9.3/libdoc/cgi/rdoc/CGI.html#method-c-escape”>http://ruby-doc.org/stdlib-1.9.3/libdoc/cgi/rdoc/CGI.html#method-c-escape</a></li></ul>

@Kamal Masser: Thank a lot! CGI.escape helps me encode the ssh_key correctly.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.