# How to generate a secure SSH key pair

> A quick note on creating a 4096-bit RSA SSH key pair with ssh-keygen, without overwriting the key you already have.

- Date: 2022-08-16
- Tags: git, tutorial, devjournal
- Also on dev.to: [https://dev.to/jimzandueta/generate-an-ssh-key-pair-2fcc](https://dev.to/jimzandueta/generate-an-ssh-key-pair-2fcc)

I make a new SSH key for every new account or server, and this is the note I come back to each time.

## Generate an SSH key pair

- Open your favorite terminal
- Run the ssh-keygen command
```sh
$ ssh-keygen -t rsa -b 4096 -C "tonystark@avengers.com"
```
> For a strong key, use the type flag `-t rsa` with the bits flag `-b 4096`. The comment flag `-C "tonystark@avengers.com"` labels the key, so you can later tell who owns it.

- Specify the key file name. The default is `id_rsa`
- Enter a passphrase _(optional, but a good idea)_

![ssh-keygen-sample](/blog/generate-an-ssh-key-pair/1.png)

> Warning: if you already have a default key at `~/.ssh/id_rsa`, do not overwrite it. You would lose SSH access to every server and Git platform that uses it. Give the new key its own name instead, such as `id_rsa_avengers`.

### Resources
- [ssh-keygen | SSH Tutorial ](https://www.ssh.com/academy/ssh/keygen)
