DEV Community

ADS-BNE
ADS-BNE

Posted on • Updated on

Explain Private and Public keys (SSH) Like I'm Five

On paper I think I understand the concept: you have a matching key file to one on a remote machine that grants you access. Yet, I've never been able to get these working. It's a mysterious box to me.

ELI5?

Top comments (2)

Collapse
 
nestedsoftware profile image
Nested Software • Edited

I think your understanding is correct. For example, on github, you can paste your public ssh key into a form on the github web site. This allows you to upload your git repositories from your computer onto github - but only if the computer you're using has the corresponding private key. Note that the key pair - the private and public key - have to be created together at the same time. The public key can be shared, but it is critical that the private key is safe and no one but the authorized user has access to it.

Collapse
 
polterguy profile image
Thomas Hansen • Edited

Both your private and public keys can encrypt, and only the other key in your key pair can decrypt whatever was encrypted with the other key. This allows people with access to your public key to encrypt data such that only the private key can decrypt whatever data was encrypted by the person encrypting it with your public key - Which is why it's important to keep your private key private, while it's important to make sure everybody has access to your (actual) public key, and not some "man in the middle" public key impersonating you ...