To start with you need to make sure you have a linux terminal with git command installed and have ability of using git command by the user at which you are trying. Always try to use a separate user and do not use root user for the same. Also you need to create a account with Github.
Create an Account with Github
To create a account with Github, you can follow the below steps
- Go to “Join GitHub”
- Fill in your information and click “Create an account”
- Select the plan you want and click “Finish sign up”
- When you sign up, you’ll receive an email to verify your email address. Click the link to complete verification.
Once account is created next step is to create a fresh key pair and then add them to Github.
Adding Your SSH Key to Your GitHub Account
Login to your terminal via SSH.
Generate a key pair by running the following command, substituting in your GitHub email address between the quotes:
When you’re prompted to “Enter a file in which to save the key,” press Enter to save it in the default location. If you wish to use a different location, you can provide the path to be used here as well.
At the prompt, type a secure passphrase that will be used when your key is authenticating, and confirm it. You can even do not setup this passphrase if you don’t need extra verification. So now you have generated the SSH key pair. Make sure you make a note on things like public key and private key files.
To add ssh key in the GitHub you need to take a copy of the public key and you can use the below ssh command to get this done.
Once you have copied the content in your clipboard or in any local text file, we can use the below steps to add the key to Github account.
- You need to login to Github Account using your user/pass
- Click on the Profile pic and select “Settings” from the Drop down.
- Select “SSH and GPG Keys” from the Menu in the left hand side
To add your first key or another key click on “New SSH key”
In the “Title” field, you need to add a label which you can remember. (I used “Sumesh’s MacBook Air”).
You can use any word and only thing you need to take care is you need to make sure that will help you to identify the machine on which that key is generated.
In “key” Field add the above key which you get by using the command “cat /home/user/.ssh/id_rsa.pub” which will start with ssh-rsa
- Click Add SSH key.
If prompted, confirm your GitHub password which will be used for verification.
Now you can see the key listed which you have added in the title name. And you will need to do the same procedure for each computer , live servers dev/staging servers which needs to access your repositories.
Check your Connection from local machine to Github
Open a new ssh terminal and make sure you switch to the user for which you had created the ssh key pair. To connect with Github account via ssh key, you need to type the below and press enter # ssh -T [email protected]
If you connecting this for the first time from that machine, you will see a result like the below and you need to type Yes in this case:
RSA key fingerprint is SHA256:asdnasd871321312kjaksjdasdijsaidjsad1Rk3ndm.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,192.30.30.1’ (RSA) to the list of known hosts.
- Type “yes”
- Press Enter
You will see output like this:
If the above mentioned user is correct and is displayed as the same one which you tried adding, then all is fine and you have completed the ssh key setup with Github ! If you are getting permission denied, then we need to cross check the above steps and make sure you have done everything as per the above doc. You can always contact me if you need any help in this case.