Skip to content

Commit

Permalink
pem readme clarification
Browse files Browse the repository at this point in the history
  • Loading branch information
bensie committed Aug 24, 2023
1 parent 49145d6 commit 6698a4e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,27 @@ k = SSHKey.generate(

### Use your existing key

Return an SSHKey object from an existing RSA or DSA or ECDSA private key (provided as a string).
Return an SSHKey object from an existing RSA or DSA or ECDSA private key (provided as a string in PEM format).

```ruby
f = File.read(File.expand_path("~/.ssh/id_rsa"))
k = SSHKey.new(f, comment: "[email protected]")
```

If your existing key is in the OpenSSH format (starts with `-----BEGIN OPENSSH PRIVATE KEY-----`), you'll need to convert it to PEM format or generate a new key.

Generate a new RSA key in PEM format with `ssh-keygen`:

```
ssh-keygen -t rsa -b 4096 -m PEM
```

Or convert an existing OpenSSH-formatted key with the following. This will modify the existing private key file.

```
ssh-keygen -p -N "" -m pem -f /path/to/existing/private/key
```

### The SSHKey object

#### Private and public keys
Expand Down Expand Up @@ -159,7 +173,7 @@ puts k.randomart

#### Original OpenSSL key object

Return the original [OpenSSL::PKey::RSA](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/RSA.html) or [OpenSSL::PKey::DSA](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/DSA.html) or [OpenSSL::PKey::EC](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/EC.html)object.
Return the original [OpenSSL::PKey::RSA](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/RSA.html) or [OpenSSL::PKey::DSA](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/DSA.html) or [OpenSSL::PKey::EC](https://ruby-doc.org/3.2.2/exts/openssl/OpenSSL/PKey/EC.html) object.

```ruby
k.key_object
Expand Down

0 comments on commit 6698a4e

Please sign in to comment.