Generate ssh key in git

Asked

Viewed 12,506 times

7

I could use a little help!

These days I was in college, committing some projects in my repository on Github through the Git, and going up some files in the repository, when I went up the last one and gave git push, it was a certain mistake:

Error: Permission denied (publickey)

I tried to see HTTP and SSH and the two were not, first time I had this problem.

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

I saw I had to set up my profile Git o SSH of the machines which are permitted to chaves públicas e prívadas for me to use the Local git And anyway, I couldn’t! Anyway, if anyone can help me by actually showing a step-by-step, knowing how to generate SSH in order to be able to use another machine and to be used, it will help me a lot! Some of the steps I’ve seen are broken, not really valid, even from Githelp, are not complete ! So if you help me by showing me step-by-step it will help.

1 answer

9


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, in the same way you would provide them when logging into the Github site; and via SSH, where you use a key pair - a public key and a private key - to authenticate without a username 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 which file you want to save your key to. If you do not have any key set, it is OK to use the default name (id_rsa). Then it will ask if you want to use a password that will be asked every time you make an authentication based on your keys. I recommend setting 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 folder ~/.ssh:

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]

Once that’s done, we’ll put the keys on Github. Log into your account, go to the settings for SSH keys and click the button Add SSH key. There you will have an optional title field and the key field, in which you should paste the public key (and not the private key) that we have 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 on Github, it is now possible to give a git push normally.

  • Thanks Rodrigo, very helpful your step-by-step and your comments, helped a lot!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.