Video Lesson: Create a new public and private key set in SSH

Create a new public and private key set in SSH

Learn how to create a secure SSH key pair for authenticating with remote systems.


Lesson Content

SSH keys provide a secure way to authenticate with a server. You can generate a new key pair with ssh-keygen:

ssh-keygen

Press Enter three times to accept the defaults. This creates the keys in their default location without a passphrase.

The keys are stored in the .ssh directory within your home directory. List the directory contents to see the generated files:

ls -la ~/.ssh

The private key is id_rsa, and the public key is id_rsa.pub. The .ssh directory and private key should only be readable and writable by your user, while the public key can be readable by other users on the system.

Never share or display the contents of id_rsa. Your private key is secret, just like a password, and anyone who obtains it may be able to authenticate as you.

You can safely share the contents of id_rsa.pub with a server or another person who needs to configure authentication for you:

cat ~/.ssh/id_rsa.pub

A public key contains the key data followed by a space and a comment. You can edit the comment at the end of the line without changing the key itself. Use it to identify the key, especially when you use different keys for multiple servers.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Log in for AI tutor access.

Comments

Join the discussion!

Notes

Keep track of what you learn!