SSH

From My Wiki
Jump to navigation Jump to search

SSH Keys

Using OpenSSH

Create a key:

ssh-keygen -t ed25519 -C "Your comment here" -f ~/.ssh/$hostname.key

Or, in RSA format:

ssh-keygen -t rsa -b 4096 -C "Your comment here" -f ~/.ssh/$hostname2.key

Make sure it has safe permissions:

chmod 600 $hostname*.key

Then for the user you want to log in as, copy the .pub file's contents to the user's .ssh/authorized_keys file. It also needs to have 600 permissions.

Using Puttygen

Linux

Install the putty-tools package if you haven't already.

Create the key:

puttygen -t ed25519 -C "Your comment here" -o ~/.ssh/$hostname.ppk

Or, in the RSA format:

puttygen -t rsa -b 4096 -C "Your comment here" -o ~/.ssh/$hostname2.ppk

Either way, the file should have 600 permissions. Print the public key:

puttygen -L ~/.ssh/$hostname.ppk

Then for the user you want to log in as, copy the output to the user's .ssh/authorized_keys file. It also needs to have 600 permissions.

Converting Between the Two

Let's say you have a public key file in OpenSSH2's native format (like PuTTY generates). Here's how to create one:

puttygen -O public testkeyforwaypoint.ppk > testkey1a.pub

You can convert it like this:

ssh-keygen -i -f testkey1a.pub > testkey2.pub

However, the converted key will have the comment stripped. Otherwise, it should match the OpenSSH private key output of the original.