# Integrate Git and GitHub through SSH Keys This section will contain the information for creating, connecting, and testing your ssh key-pair between your computer and GitHub. ## Step 1: Creating an SSH key-pair Let's generate those keys! Place the following command into your terminal and change the email to your GitHub account's email. ``` ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` ``` ssh-keygen -t ed25519 -f ~/.ssh/id_sts115 -C "your_email@example.com" ``` After running the command, you should receive the prompt: ``` Enter file in which to save the key (/home/baumlerc/.ssh/id_rsa): ``` Here you have two choices: 1. leave it blank (by hitting enter without **any** text) for the SSH keys to be named "id_rsa" and "id_rsa.pub". 2. add a descriptor to the file name I am going to give my keys a descriptive name, `a-name-i-will-remember-that-this-key-is-for-github-access`. ``` Enter file in which to save the key (/home/baumlerc/.ssh/id_rsa): a-name-i-will-remember-that-this-key-is-for-github-access ``` You will now be prompted to create a passphrase. Leave this blank by hitting `enter` on your keyboard. It is an added layer of security we do not need to worry about. ``` Enter passphrase (empty for no passphrase): Enter same passphrase again: ``` The final output should be similar to this: ``` Your identification has been saved in a-name-i-will-remember-that-this-key-is-for-github-access Your public key has been saved in a-name-i-will-remember-that-this-key-is-for-github-access.pub The key fingerprint is: SHA256:On9N22rdLVIpUqQQ/1Hnytm9H5TKcAnsfNDA8P/B5Es your_email@example.com The key's randomart image is: +---[RSA 4096]----+ | .oo. . .| | ..o.+. o | | ..B.. ..| | +.=o=+o| | S =.=+Eo| | . . B B +| | o + O *.| | o . = + =| | .. ..o ..| +----[SHA256]-----+ ``` Great! Now you have a private and public SSH key in your `.ssh` directory on your computer. You can see these files with the following command: ``` ls ~/.ssh ``` ## Step 2: Connecting the ***Public*** key to GitHub To utilize the SSH key for GitHub access, you will need to copy your ***public*** key and give it to GitHub. Start by printing the public key file (the SSH key that ends in `.pub`): ``` cat ~/.ssh/a-name-i-will-remember-that-this-key-is-for-github-access.pub ``` OR ``` cat ~/.ssh/id_rsa.pub ``` The output should look something like: ```! ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCuGB9i8OyR4YlCH/pDTxWUcz8CS+zAz2WUqaKDyKkDs5uUbo9hqQSIKrAmKyTvRtK3TQVN2QQtqr9KznwvFRJ5UfcBvgerZSb/ZaVisr7xxAbszv7bn4NT9S1rwBAdzedYxEbKBFXHhQ/KfCYayrcaA7Je3h8Gtl41Ss0SYn4M0b4UYlrzjzIGc6dK5CsoUU0B1+GJaSsmMD8WpiCm1O0E4f7MTlCQ1fpzNZpr+Hui4DBLUBYpBj6ehZpv97Su2jAFFECW70rVjIiEb2BAgXdYtPA/SgnjIrpWCSF2G3eV4TUkFrSyXK0tYmiM/ZA81JY83DBf7UBOEW2h+6DE8A5uRLyK9mbbPDg8BBPAOtpZ+m6VRnwn8eM0YQgHkHPTdONx0L/yan1pJ/PHwefq+JsL18e3VdxDBQ5vEsKxb3c7FIIM/l2agyyzsSYkvo5hizjFEPqnrvUf5VtdPR3STWNM3KjsAFF7SlZGXkRcFBYuvwU6jwt46YdpltoLdcvbZ7LNcT8NRmb8tm8hjpwIzbKjl3fkwUJsDSL/m4JWDYByztf4PIKWacpTbPG/H8X8VPFg2QOxzfhOIQDIJatKYb0lCv18VZOup5vziFOAhAmpEhXuCb3EgIBHyTzB/vR0aLo/V4tZ7J+1dCaAyJY3My5Br1AphR+tzwcxyibyzhJH/w== your_email@example.com ``` **Copy this output!!** Now navigate to your GitHub profile key setting at https://github.com/settings/keys. Click the `New SSH key` box in the upper right. ![image](https://hackmd.io/_uploads/BkMBw-kP1l.png) Add a descriptive title in the `Title` section (i.e. Local or Local-key) Paste your copied public key into the `Key` section. Finally, click the `Add SSH key` button at the bottom of the site. ![image](https://hackmd.io/_uploads/SyOcDWJPJl.png) ## Step 3: Testing your connection After completing the previous two steps you should now be connected to GitHub with your local computer. Before moving on to better things, it's good practice to test what you just did. Let's check your connection with: ``` ssh -T git@github.com ``` You should receive the following output. ``` Hi ccbaumler! You've successfully authenticated, but GitHub does not provide shell access. ``` If you need to debug your connection, try the more verbose output of: ``` ssh -vT git@github.com ``` For further reading on the subject of SSH key generation, and Github SSH key settings. - https://www.ssh.com/academy/ssh/keygen - https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent - https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account # Debugging Permissions denied! ``` eval "$(ssh-agent -s)" ``` ``` ssh-add ~/.ssh/<key-name> ```