I've been using GitHub only through HTTPS which can start to be quite annoying (as I didn't setup my password so I need to input it every single time I pull or push).
So I'm following the steps in this link:
https://help.github.com/articles/generating-ssh-keys
so first I checked if I already had keys generated for GitHub by running the following command in my Mac:
ls -al ~/.sshAll the keys I got back I know where they are from and so I had no keys already being used for GitHub
So the next step is to generate a new SSH key by running the command:
ssh-keygen -t rsa -C "your_email@host.com"Please use your own email (the one for your GitHub account).
When asked for a name of a file just press <Enter>
and then input a strong password.
After that we need to run two more commands in our machine so the key will automatically be available in the system.
First we launch the ssh agent in the background by using the command:
eval "$(ssh-agent -s)"Then we add our key to it by running the command:
ssh-add ~/.ssh/id_rsaplease note that the name id_rsa is the default and if you inputed a name for the file this will have to match that name.
You'll also be prompted for the password that you defined in the previous step.
So on your machine everything is setup, you now need to set it up in Github.
So you start by adding the key to your clipboard by running the command:
pbcopy < ~/.ssh/id_rsa.pubNow you go to your GitHub Admin page ( https://github.com/settings/admin) and choose SSH Keys in the left menu.
You click on the button "Add SSH Key"
On the title you should put the correct description from where this key is coming from, this way you'll be able to manage the keys when you change computer or company.
On the field key you should past the key you copied with the command pbcopy.
Press the button "Add Key" , you'll be prompted for your GitHub password and then you should have successfully added a new SSH Key to your GitHub Account.
Finally if you are like me, you have been using your repositories through HTTPS and now you would like to just change that to SSH without any hassle.
First navigate in the terminal to the folder that is the root of your project.
When there run the command
git statusto make sure you are in the correct place. Then run the command:
git remote -vThis will return something like:
Now we run the command that will change it from HTTPS to SSHorigin https://github.com/username/repository.git (fetch)origin https://github.com/username/repository.git (push)
git remote set-url origin git@github.com:username/repository.gitIf we now run the command:
git remote -vYou'll see something like this:
origin git@github.com:username/repository.git (fetch)Which means the new repository is already set. Now you can just push, pull, fetch, checkout and other git commands without having to put in your password.
origin git@github.com:username/repository.git (push)