Set up SSH for GitHub in the Terminal

Verify the existence of the directory ~/.ssh

Let’s verify if we have a directory called .ssh in the root (cd ~).
We can verify by changing to that directory cd ~/.ssh

Creating the .ssh directory

If we don’t have the director…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Emmanuel Morales

Verify the existence of the directory ~/.ssh

  • Let's verify if we have a directory called .ssh in the root (cd ~). We can verify by changing to that directory cd ~/.ssh

Creating the .ssh directory

  • If we don't have the directory then we create it: mkdir ~/.ssh.

Generate a new key

  • If we have the directory, then we generate a key by
ssh-keygen
  • We press ENTER to save the key in our directory /Users/user-name/.ssh/id_rsa

  • If we want a password that protect the key, we enter a passphrase and click ENTER, and we repeat the same passphrase settled later and press ENTERagain.

    • If we don't want to, we just left it empty and press ENTER.

Add the public password to Github

  • Look and copy the public password:
cat id_rsa.pub

Image description

  • We go to Settings profile:
    Image description

  • Then we move to SSH and GPG keys:
    Image description

  • And we add a New SSH key by adding a Title, the use of that key (in our case Authentication key), and the public key generated from the public password (cat id_rsa.pub).
    Image description

    • Note: The key we use is the public one, from the id_rsa.pub, NOT the id_rsakey.

Adding an agent to hold the ssh key.

An agent holds the public and private key for authenticate into services, in our case GitHub.

  • Start the agent:
eval $(ssh-agent -s)

Image description

  • Add the password to the agent:
ssh-add ~/.ssh/id_rsa

Image description

Testing

Now in our session is validated to use push and clone our public and private repositories

Basic Test

git init
git add .
  • Then we add the SSH link from a GitHub Repository:
git remote add origin git@github.com:user/Repo_Name

Image description

  • We make our commit:
git commit -m "First Commit"

So when we do some git push -u origin master the authentication will be settled.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Emmanuel Morales


Print Share Comment Cite Upload Translate Updates
APA

Emmanuel Morales | Sciencx (2022-09-17T19:49:16+00:00) Set up SSH for GitHub in the Terminal. Retrieved from https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/

MLA
" » Set up SSH for GitHub in the Terminal." Emmanuel Morales | Sciencx - Saturday September 17, 2022, https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/
HARVARD
Emmanuel Morales | Sciencx Saturday September 17, 2022 » Set up SSH for GitHub in the Terminal., viewed ,<https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/>
VANCOUVER
Emmanuel Morales | Sciencx - » Set up SSH for GitHub in the Terminal. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/
CHICAGO
" » Set up SSH for GitHub in the Terminal." Emmanuel Morales | Sciencx - Accessed . https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/
IEEE
" » Set up SSH for GitHub in the Terminal." Emmanuel Morales | Sciencx [Online]. Available: https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/. [Accessed: ]
rf:citation
» Set up SSH for GitHub in the Terminal | Emmanuel Morales | Sciencx | https://www.scien.cx/2022/09/17/set-up-ssh-for-github-in-the-terminal/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.