# Git Hub Using SSH

### 1. Use Personal Access Tokens (PAT)

You can create a Personal Access Token in GitHub and use it instead of your password. Here's how:

1. **Generate a Personal Access Token:**
    
    
    - Go to your GitHub account settings.
    - Navigate to **Developer settings** &gt; **Personal access tokens** &gt; **Tokens (classic)**.
    - Click on **Generate new token**.
    - Select the scopes/permissions you need (for repository access, select <span class="
                  font-mono 
                  text-text-800 
                  bg-background-50 
                  border 
                  border-background-300 
                  rounded 
                  align-bottom
                  px-1
                  py-[3px]
                  text-xs 
                  inline-block
                  whitespace-pre-wrap 
                  break-words 
                  
                ">repo</span>).
    - Click **Generate token** and make sure to copy the token (you won’t be able to see it again).
2. **Use the Token for Authentication:** When prompted for a username and password in the terminal:
    
    
    - Use your GitHub username as the username.
    - Use the generated token as the password.

### 2. Use SSH Authentication

Alternatively, you can use SSH keys for authentication. Here’s how to set it up:

1. **Generate an SSH Key (if you don’t have one):**
    
    <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
    ssh-keygen -t rsa -b 4096 -C "cto@issentialsolutions.com"
    ```
    
    Follow the prompts to save the key (usually in <span class="
              font-mono 
              text-text-800 
              bg-background-50 
              border 
              border-background-300 
              rounded 
              align-bottom
              px-1
              py-[3px]
              text-xs 
              inline-block
              whitespace-pre-wrap 
              break-words 
              
            ">~/.ssh/id\_rsa</span>).
2. **Add the SSH Key to your GitHub Account:**
    
    
    - Copy the SSH key to your clipboard: <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
        cat ~/.ssh/id_rsa.pub
        ```
    - Go to GitHub settings &gt; **SSH and GPG keys** &gt; **New SSH key**.
    - Paste the key and give it a title.
3. **Clone the Repository Using SSH:** Change the repository URL to use SSH:
    
    <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
    git clone git@github.com:krishnaaka-online/is-odoo.git
    ```

### To See the private Key

```
cat ~/.ssh/id_rsa
```


### Summary

Choose either Personal Access Tokens or SSH authentication to resolve the authentication issue. If you frequently use GitHub, SSH is often more convenient, while PATs are simpler for one-off uses.

### Steps to Configure Host Key Verification in Jenkins

1. **Access Jenkins Configuration:**
    
    
    - Open your Jenkins dashboard in a web browser.
    - Go to **Manage Jenkins**.
2. **Configure Git Host Key Verification:**
    
    
    - In the **Manage Jenkins** section, look for **Security** or **Git Host Key Verification Configuration**.
    - If you don't see this option, you might need to install the **Git Plugin** or check the plugin settings.
3. **Add GitHub to Known Hosts:**
    
    
    - You need to add the GitHub host key to the <span class="
                  font-mono 
                  text-text-800 
                  bg-background-50 
                  border 
                  border-background-300 
                  rounded 
                  align-bottom
                  px-1
                  py-[3px]
                  text-xs 
                  inline-block
                  whitespace-pre-wrap 
                  break-words 
                  
                ">known\_hosts</span> file. You can do this manually or through Jenkins: 
        - **Manually:**
            - Open a terminal on the Jenkins server and run: <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
                ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts
                
                ```
            - Ensure that the file exists and is correctly populated.
        - **Through Jenkins:**
            - If the Jenkins interface allows, you can add the host key directly there.
4. **Verify the Known Hosts File Exists:**
    
    
    - Ensure that the <span class="
                  font-mono 
                  text-text-800 
                  bg-background-50 
                  border 
                  border-background-300 
                  rounded 
                  align-bottom
                  px-1
                  py-[3px]
                  text-xs 
                  inline-block
                  whitespace-pre-wrap 
                  break-words 
                  
                ">known\_hosts</span> file exists at the expected location. If the file does not exist, create it: <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
        touch ~/.ssh/known_hosts
        
        ```
    - Then, add the GitHub host key as mentioned above.
5. **Test SSH Connection:**
    
    
    - On the Jenkins server, test the SSH connection to GitHub: <div class="overflow-x-hidden"><div class="flex mx-3 py-2 text-xs">bash</div></div>```
        ssh -T git@github.com
        
        ```
    - You should see a message indicating successful authentication.
6. **Check Permissions:**
    
    
    - Ensure that the user running Jenkins has permission to read the <span class="
                  font-mono 
                  text-text-800 
                  bg-background-50 
                  border 
                  border-background-300 
                  rounded 
                  align-bottom
                  px-1
                  py-[3px]
                  text-xs 
                  inline-block
                  whitespace-pre-wrap 
                  break-words 
                  
                ">~/.ssh/known\_hosts</span> file and that the file has the correct permissions set (typically <span class="
                  font-mono 
                  text-text-800 
                  bg-background-50 
                  border 
                  border-background-300 
                  rounded 
                  align-bottom
                  px-1
                  py-[3px]
                  text-xs 
                  inline-block
                  whitespace-pre-wrap 
                  break-words 
                  
                ">600</span>).

### Summary

By configuring the host key verification in Jenkins and ensuring that the <span class="
          font-mono 
          text-text-800 
          bg-background-50 
          border 
          border-background-300 
          rounded 
          align-bottom
          px-1
          py-[3px]
          text-xs 
          inline-block
          whitespace-pre-wrap 
          break-words 
          
        ">known\_hosts</span> file is properly set up, you should be able to resolve the host key verification issue and allow Jenkins to clone the GitHub repository successfully. If you continue to encounter issues, double-check the SSH keys and permissions.