title | author | date | tags | summary | ||||
---|---|---|---|---|---|---|---|---|
Configuring git |
Luna L. Sanchez-Reyes |
2022-02-01 |
|
To check if we have an ssh authentication already we run on the terminal:
ssh -T git@github.com
If we have the ssh authentication we will a message like this:
Hi User Name! You've successfully authenticated, but GitHub does not provide shell access.
If it is not succesful, follow to the next section.
We will write the following command by replacing the email within quotations with the email we used to sign up on github. It is important to keep the quotations around the email:
ssh-keygen -t ed25519 -C "your_email@email.com"
The computer will ask:
Enter file in which to save the key (/Users/lunasare/.ssh/id_ed25519):
Leave it empty and type return
.
The computer will then ask for a passphrase. Make sure to write one down, do not leave this one empty.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
The following command starts the authetication agent:
eval "$(ssh-agent -s)"
To automatically load keys into the ssh-agent and store passphrases in our keychain, we need a "~/.ssh/config" file
To check if we already have it we run:
ls ~/.ssh/config
If it does not exist, the command above will return an error, and we can proceed to create a file with:
touch ~/.ssh/config
Now we will open the "~/.ssh/config" file with a text editor and add the following text:
Host *
AddKeysToAgent yes
IgnoreUnknown UseKeychain
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
Back in the terminal, we can add our SSH private key to the ssh-agent and store our passphrase in the keychain with the next line of code:
ssh-add -k ~/.ssh/id_ed25519
Copy/paste the numeric part that outputs from:
cat ~/.ssh/id_ed25519.pub
Now, go to your GitHub profile and add the SSH key you just copied.
Finally, we can check again that our ssh authentication is working with:
ssh -T git@github.com
From your GitHub account, go to Settings => Developer Settings => Personal Access Token => Generate New Token (Give your password) => Fillup the form => click Generate token => Copy the generated Token, it will be something like ghp_sFhFsSHhTzMDreGRLjmks4Tzuzgthdvfsrta
You can save your token in a text file in your computer.
Use the token as your password next time you do git push
. Follow the steps below to save this token in your git cache for the future.
For a Linux-based OS ⤴ For Linux, you need to configure the local GIT client with a username and email address,
$ git config --global user.name "your_github_username"
$ git config --global user.email "your_github_email"
$ git config -l
$ git config --global credential.helper cache
If needed, anytime you can delete the cache record by:
$ git config --global --unset credential.helper
$ git config --system --unset credential.helper