Generate PEM file for any Linux user

Quickly and easily generate a key pair for passwordless connection. Also works perfect as git deploy keys!

Generate the keys

DO NOT DO THIS AS ROOT

Run the command to generate the keys

1
$ ssh-keygen -P "" -t rsa -b 4096 -m pem -f my-key-pair
  • -b flag sets the bits, 4096 is recommended
  • -m pem is needed to generate a file in RSA Private Key format, not in OpenSSH Private Key format
  • -f specifies the output key pair
  • replace my-key-pair with the name of your key pair (preferably deploy_key or access_key)

This will generate two files:

  • my-key-pair - this is your PEM file, copy paste the contents
  • my-key-pair.pub - this is the corresponding public key file

Note: You may want to rename the my-key-pair to my-key-pair.pem for convenience.

Set the key to allow login

In order to be able to log in using the generated PEM file, you should add the public key to the authorized_keys list. To do that, run

1
2
3
4
# Ignore this step if you have other public keys added
$ touch ~/.ssh/authorized_keys

$ cat my-key-pair.pem >> ~/.ssh/authorized_keys
Licensed under CC BY-NC-SA 4.0
All content is licensed under CC BY-NC-SA 4.0. Copying is an act of love - please copy!
More cool websites: Prev | Hotline Webring | Next
Built with Hugo
Theme Stack designed by Jimmy