> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/shell00/ssh-me.md).

# SSH me!

**Objective:**

The goal of this exercise is to create an SSH key and understand how to use it for secure communication with remote servers, particularly for pushing code to a Git repository.

**Instructions:**

1. **Create an SSH Key:**
   * You need to generate an SSH key pair (public and private keys) on your local machine.
   * The public key will be shared with the remote server (in this case, the Git server), while the private key remains securely on your machine.
2. **Add the Public Key to Your Repository:**
   * Once the SSH key is generated, you need to add the public key to your Git repository. This is done by creating a file named `id_rsa_pub` in your repository and pasting the public key into it.
3. **Update Your SSH Key on the Intranet:**
   * After adding the public key to your repository, you need to update your SSH key on the intranet. This step ensures that the Git server recognizes your machine and allows you to push code securely.

**Detailed Steps:**

1. **Generate an SSH Key:**
   * Open your terminal and run the following command to generate an SSH key:

     ```
     ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
     ```
   * When prompted, press Enter to save the key in the default location (`~/.ssh/id_rsa`).
   * You can optionally set a passphrase for added security.
2. **Add the Public Key to Your Repository:**
   * After generating the key, you can display the public key by running:

     ```
     cat ~/.ssh/id_rsa.pub
     ```
   * Copy the output (this is your public key).
   * Create a file named `id_rsa_pub` in your submission directory (`ex03/`) and paste the public key into this file.
3. **Update Your SSH Key on the Intranet:**
   * Log in to your intranet account and navigate to the SSH key settings.
   * Add the public key you copied earlier to your intranet profile. This step ensures that the Git server recognizes your machine.
4. **Test Your SSH Connection:**
   * To verify that your SSH key is working correctly, you can test the connection to the Git server:

     ```
     ssh -T git@git.example.com
     ```
   * If everything is set up correctly, you should see a success message.

**What You Will Learn:**

* **SSH Key Generation:** You will learn how to generate SSH keys, which are essential for secure communication between your local machine and remote servers.
* **Public and Private Keys:** You will understand the difference between the public key (which is shared) and the private key (which must remain secure).
* **Git Integration:** You will learn how to integrate SSH keys with Git, allowing you to push code securely to remote repositories.
* **Security Best Practices:** You will learn the importance of using SSH keys for secure authentication and how to manage them effectively.

**Useful Resources:**

* [**SSH Keygen Guide**](https://www.ssh.com/academy/ssh/keygen)**:** A comprehensive guide on generating and managing SSH keys.
* [**Git and SSH Keys**](https://docs.github.com/en/authentication/connecting-to-github-with-ssh)**:** GitHub's official documentation on using SSH keys with Git.
* [**SSH Essentials**](https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys)**:** A detailed tutorial on working with SSH servers, clients, and keys.
* [**Understanding SSH Keys**](https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process)**:** An article that explains the encryption and connection process behind SSH.

**Conclusion:**

This exercise is a fundamental step in understanding how to securely manage remote connections, especially when working with Git. By completing this exercise, you will gain practical experience in generating SSH keys, managing them, and integrating them with Git for secure code pushes. This knowledge is crucial for any developer working in a collaborative environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/shell00/ssh-me.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
