So, Someone Asked You for Your Public Key.
So, Someone Asked You for Your Public Key.
So, someone asked you for your public key, and you’re pretty sure they want your SSH public key, but you don’t really know what to do.
This simple guide will walk you through creating a new OpenSSH RSA keypair that you can use to do things like login to servers using your key instead of a password.
Step 1: Get Specific
First, find out exactly what they want from you.
- Ask them: Do you want my SSH public key, or another public key, like PGP? If they say “SSH”, keep reading! You’ll use an SSH key to do things like access a server. (If they say something else like “PGP”, ask them for instructions.)
- Ask them: Do you want my SSH public key, or another public key, like PGP? If they say “SSH”, keep reading! (If they say something else, ask them for instructions.)
- Ask them: Do you want my public key in OpenSSH format? If they say “yes” (or “I don’t know”) to OpenSSH format, keep reading! (If they say no, ask them for instructions.)
Step 2: Find Your Keypair, or Make a New One
Next, check to see if you already have any SSH keypairs set up.
Open the command line and run ls -la ~/.ssh
to list the contents of your .ssh
directory.
Do you see id_rsa.pub
listed?
If you do, you already have a key pair! Move on to Step 3.
If you don’t, you need to generate a new key pair.
Run ssh-keygen -t rsa -C "you@example.com"
, using your email address instead of you@example.com.
Follow the instructions on-screen. Save your keypair to ~/.ssh/id_rsa
. You must set a strong passphrase on your key.
When ssh-keygen is done, move on to Step 3.
Step 3: Learn About Your Keypair
Great! You now have an SSH keypair.
Your public key is the ~/.ssh/id_rsa.pub
file. This file is safe to share with anyone, it does not need to be protected. The contents of your id_rsa.pub
file will look something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5Jleo8D72veOZ0M722YJTYkIfADhrNLp0BK1cwQWKA/PmuaS+TkluazBprDdpI5vcSQMRH/k+aWVlxBLsLq2e3vbdtyFsFSWJyG0xlwBQPpIpSK9Z92hwWce8wgbzmwBmxRWcdax16OMrn4IEYRMd9WQCrpO3JW5mtKKckyy1JjrljDA7YIqQpyoluvkjm/fosm0jEsBwcaYYg32Yu1aX/eqzxpTVlBsEI29pc3fiIsUajVRYND9FY23uiLSDH4O+UkHFlbAw+Y5WLmZDccIU+p2UsjdDKZEDImbQvQBDKV7LQavFlhPHSb9CDKl4JmZeFUGKHUSb3Q60N6lWBP you@example.com
Your private key is the file ~/.ssh/id_rsa
. Your private key is private and should be kept safe, like a password! It just belongs to you! Don’t give it to anyone, and don’t send it over the internet. The contents of your id_rsa
file will look something like this:
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAuSZXqPA+9r3jmdDO9tmCU2JCHwA4azS6dAStXMEFigPz5rmk
vk5Jbmswaaw3aSOb3EkDER/5PmllZcQS7C3XWupFTA04aAD+LXCchtMZcAUD6SKU
LVKhkJXVwlBFgB42wa1xKUn9ihB+ZVdBZ2rCkmvAvC1t4znHILBqEnmWGaBEMp9g
ivWfdocFnHvMIG85sAZsUVnHWsdejjK5+CBGETHfVkAq6TtyVuZrSinJMstSY65Y
wwO2CKkKcqJbr5I5v36LJtIxLAcHGmGIN9mLtWl/3qs8aU1ZQbBCNvaXN34iLFGo
vwSKyq8RrjkSg6Lv+od3k60CgYBQGi2/++7m8PXo1fC7B4PqqiJz1zCBGLpsx2JR
YBEn3IAf8EUSS6awhVjFHpHl216KNxHz/DOKX2G3crlz+Go67l49hI/DXd6KL42d
qCcGGQKBgQCKdT//RYKADjg7ASFcRQsIVGDN9tVv//qedl7Y2zKiz9NxX7zFAri2
vHZUWnKO378T8bv1rtSrUElo2XIZLrSdht6itdcd4fkGja7qD53/+qsy18VSWLws
uagnPiavWaMrd1s+AHYE9Ar1j5cogvjrY/9KvcF6g5TtHm0ngE1IHw==
-----END RSA PRIVATE KEY-----
Step 4: Send Your Public Key
You can now provide your public key to the person who asked you for it. You can:
- Open your public key — the
~/.ssh/id_rsa.pub
file — with a text editor. Select the contents, copy to your clipboard, and paste into a message to the person that requested it. - Send your public key — the
~/.ssh/id_rsa.pub
file — to the person that requested it.
Remember: DO NOT send your id_rsa
file! Keep it safe, it belongs to you only.