Programster's Blog

Tutorials focusing on Linux, programming, and open-source

SSH Agent Cheatsheet

SSH Agent (ssh-agent) is a really useful tool for managing your SSH keys, so that you can quickly log into systems that use private SSH keys. This is especially useful in the world of CI/CD when one needs to access private repositories through SSH keys when tokens can't be used.

Unfortunately, all the options are "shorthand", and there are no longhand equivalents. E.g. -D to delete, instead of --delete.

Table of Contents

Key Management

Add Key

ssh-add my-private-key

If this private key required a passphrase, you will be prompted for it.

Remove Key

ssh-add -d my-private-key

List Keys

If you want a short list of the key length, hash, and name, then use:

ssh-add -l
3072 SHA256:XXXXXXXXXXXXXXXXXXXX8Havf+G/ydzf7pXihNyxEf4 programster@stu-bitfenix (RSA)
2048 SHA256:XXXXXXXXXXXXXXXXXXXXCierjcubIBVI7Z1cy8skMNY programster@stuart-r7-1700 (RSA)

If you want the full public keys to be output, then use:

ssh-add -L

References

Last updated: 23rd August 2022
First published: 29th July 2021

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch