> For the complete documentation index, see [llms.txt](https://hacking-3.gitbook.io/barre/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-3.gitbook.io/barre/apuntes/general/redes/protocolos/ssh/ssh-public-key.md).

# SSH Public Key

## **Steps to Create an SSH Public Key on Linux/macOS**

### **Generate the SSH key pair**

```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

Command explain:

* `-t rsa`: Specifies the type of key, in this case RSA (you can use other types like ed25519).
* `-b 4096`: Specifies the key size in bits (4096 is a secure size for RSA).
* `-C "your_email@example.com"`: An optional comment added to the public key for identification (typically an email address).

### **Save the keys**

After running the command, you’ll be prompted to choose a location to save the key pair. You can press Enter to accept the default location.

{% hint style="success" %}
By default, it will be saved to `~/.ssh/id_rsa` (private key) and `~/.ssh/id_rsa.pub` (public key).
{% endhint %}

### **Protect the private key with a passphrase (optional)**

The system will prompt you to enter an optional passphrase to protect your private key.\
You can leave it blank if you prefer not to use one, but it is recommended for security purposes.

### **Generated key**

Once you've completed the above steps, you’ll have two files:

* `~/.ssh/id_rsa`: Your private key. This should be kept secure and never shared.
* `~/.ssh/id_rsa.pub`: Your public key. This is the key you’ll share with the servers you want to connect to.

***

## **Viewing the Public Key**

To view the content of the public key (usually found at `~/.ssh/id_rsa.pub`), use the following command:

```bash
cat ~/.ssh/id_rsa.pub
```

The content of this file is what you need to add to the `~/.ssh/authorized_keys` file on the servers you want to connect to.

***

### **Example of an SSH Public Key**

An RSA public key looks something like this:

```
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC0...truncated...xample+user@domain.com
```

This is the value you would share so others can authenticate using your public key, while you keep the private key to securely authenticate.
