Generate ssh key in git

5

I'm in need of some help!

These days I was in college, committing some projects in my GitHub repository through Git , and uploading some files to the repository, when I was uploading the last one and give git push , gave a certain error:

  

Error: Permission denied (publickey)

I tried HTTP and SSH and both were not, the first time I had this problem.

I already looked at some steps on the internet, both videos and tutorial, I did some and it continued the same thing, with the key error not allowed when I was on this machine there in college.

I saw that I had to configure in the profile of my Git o SSH of the machines that are allowed of chaves públicas e prívadas to use the local Git and finally I could not! Anyway, if someone can help me, really showing a step-by-step , knowing how to generate SSH to enable use on another machine and be usable, will help me a lot! Some steps I've seen, are broken, are not really valid, even the very GitHelp , they are not complete! So if you help me by showing a step-by-step will help.

    
asked by anonymous 17.08.2015 / 09:09

1 answer

6

As you said, there are two ways to authenticate to GitHub when you push: via HTTP and via SSH. Via HTTP you provide your credentials, just as you would when you log in to the GitHub website; and via SSH, in which you use a pair of keys - one public and one private - to authenticate without a user and password.

First, we must generate a new key pair using the command ssh-keygen :

ssh-keygen -t rsa -b 4096 -C "[email protected]"

The command will ask you which file you want to save your key to. If you do not have any keys configured, it is okay to use the default name ( id_rsa ). It will then ask if you want to use a password that will be asked every time you authenticate based on your keys. I recommend setting up a password if you share your computer with others.

Enter passphrase (empty for no passphrase): [digite sua senha]
Enter same passphrase again: [digite sua senha novamente]

Finally, your key will be saved in the ~/.ssh folder:

Your identification has been saved in /Users/raffa-ferreira/.ssh/id_rsa.
Your public key has been saved in /Users/raffa-ferreira/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]

After that, let's put the keys in GitHub. Log in to your account, go to the SSH Keys settings and click the Add SSH key button. There you will have an optional title field and the key field in which you should paste the public key (not the private one) that we just generated. To facilitate the process, copy the public key to the clipboard using the command pbcopy :

pbcopy < ~/.ssh/id_rsa.pub

Once your key has been set up in GitHub, it is already possible to give a git push normally.

    
17.08.2015 / 22:40