Creating Your First GitHub Repository with SSH Authentication π±π
Set up Git and GitHub
Install Git π
First things first, you need Git on your machine:
Windows: Download the Git installer from the official Git website and follow the installation prompts.
Linux: Use your distribution's package manager with
sudo apt-get install git
With Git installed, open a terminal and configure your user name and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Creating a GitHub account π±
If you haven't already, head over to GitHub and sign up.
Link Git with GitHub π
To connect your local Git environment with GitHub, you can use HTTPS or SSH. While HTTPS is straightforward, SSH offers a more secure and convenient method of authentication.
HTTPS method π
HTTPS stands for Hypertext Transfer Protocol Secure. It is the protocol used for secure communication over the internet.
It does not need any additional configuration, so you can start using it immediately after setting up your Git and GitHub accounts. Another advantage is that it works in almost any network environment without needing special permissions.
However, it requires frequent authentication (entering your username and password) which can be cumbersome for those who plan to push to GitHub frequently.
SSH method π
SSH stands for Secure Shell. It is a protocol used for secure login and communication over an unsecured network. When using SSH with Git and GitHub, you create a pair of SSH keys (a public key and a private key) and add the public key to your GitHub account. This setup allows secure, password-less communication with GitHub.
It is secure and it is very convenient for frequent use as once set up, you don't need to enter your credentials again for every push or pull.
However, it some corporate restricted networks block SSH traffic, which could require additional configuration or switching to HTTPS.
Step-by-step guide to set up SSH keys ποΈ
Open terminal:Git Bash on Windows or the default terminal on Linux
Generate a new SSH key: Enter the following command, replacing
your_email@example.com
with your GitHub email address:ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
When prompted to "Enter a file in which to save the key," press Enter to accept the default file location.
Start the SSH agent: Before adding your SSH key to the agent, ensure the ssh-agent is running by executing:
eval $(ssh-agent -s)
Change the file permissions of the private key: SSH requires that the private key file is not accessible by others for security reasons.
chmod 600 ~/.ssh/id_rsa
Add your SSH key to the SSH agent: Run the following command:
ssh-add ~/.ssh/id_rsa
Copy the SSH key: Run this code to display your SSH key in the terminal, which you can then manually copy.
cat ~/.ssh/id_rsa.pub
Add Your SSH Key to GitHub: Go to your GitHub account, navigate to Settings > SSH and GPG keys > New SSH key, paste your key into the field, give it a title, and click "Add SSH key."
Creating your first repository π
Log in to GitHub and create a new repository:
Once logged in to GitHub, click the "+" icon in the upper right corner and select "New repository."
Name your repository, add a description (optional), and decide if it will be public or private.
Click "Create repository."
Push an existing repository from the command line:
Open terminal and change the current working directory to your local project.
Initialize the local directory as a Git repository, if you haven't already:
git init
If you do not have any files in your project yet, you can add simple
README.md
:echo "# Project Title" > README.md
Add the files in your new local repository. This stages them for the first commit:
git add .
Commit the files that you've staged in your local repository:
git commit -m "First commit"
Copy the SSH URL of your repository from GitHub, which looks like
git@github.com
:username/repository-name.git
.Add the URL as a remote repository for your project:
git remote add origin git@github.com:username/repository-name.git
Push the changes in your local repository to GitHub:
git push -u origin main
Now that you've set up SSH authorization and created your first repository, you can start collaborating on projects more securely and efficiently π«.
Subscribe to my newsletter
Read articles from Natasha Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Natasha Sharma
Natasha Sharma
I'm an AI Engineer with a passion for turning data into actionable insights. I specialize in developing Python scripts for data analysis, training algorithms, and making predictions. I enjoy designing and executing Proof of Concept (PoC) projects, and I always aim to align technical solutions with business goals. With a Masterβs degree in Artificial Intelligence, I'm always eager to learn new things and take on new challenges. Iβm organized, detail-oriented, and thrive under pressure.