Emmanuel Morales
Posted on September 17, 2022
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 directorycd ~/.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 pressENTER
again.- If we don't want to, we just left it empty and press
ENTER
.
- If we don't want to, we just left it empty and press
Add the public password to Github
- Look and copy the public password:
cat id_rsa.pub
-
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
).
-
Note: The key we use is the public one, from the
id_rsa.pub
, NOT theid_rsa
key.
-
Note: The key we use is the public one, from the
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)
- Add the password to the agent:
ssh-add ~/.ssh/id_rsa
Testing
Now in our session is validated to use push
and clone
on 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
- We make our commit:
git commit -m "First Commit"
So when we do some git push -u origin master
the authentication will be settled.
Posted on September 17, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.