Push Codes from Linux (UBUNTU) To GitHub using SSH KEY
Last Updated :
17 May, 2024
GitHub, one of the most popular platforms for version control and collaboration, offers multiple authentication methods for interacting with repositories. SSH keys provide a secure and convenient way to authenticate and push code from a local machine to GitHub. In this article, we'll learn the step-by-step process of pushing code from Linux (Ubuntu) to GitHub using SSH keys.
What is an SSH Key?
The safest way to connect to GitHub and push/pull code is by using an SSH key. SSH (Secure Shell) is an encryption protocol used to provide secure remote login between computers. SSH key is a pair of cryptographic keys that you can use to authenticate a user to a remote system. Generating an SSH key gives you a public key and a private key. The public key must first be published on GitHub, whereas the private key must be kept on your personal machine. With an SSH key based on the protocol that you use to connect with GitHub, you can easily validate your identity and push/pull code from GitHub, without entering your username and password.
Steps to Push Codes from Linux (UBUNTU) To GitHub using SSH KEY.
Step 1: Go to the project folder you wish to push to GitHub. From the folder generate an ssh-key by opening the terminal in that folder and executing this command.
ssh-keygen -t rsa -b 4096 -C <your email>
Generate SSH keyStep 2: Register a new private key using this command.
eval "$(ssh-agent -s)"
Register private keyStep 3: Now add the private key to ssh-agent by executing this command.
ssh-add ~/.ssh/id_rsa
add the private key to ssh-agentStep 4: Create a new Repo on you github from the official website. Let's name the repo "Testing".
Step 5: Now we have to create a connection between our computer and the github. For this type the following command.
- "git init" initializes a new Git repository in the current directory, allowing you to track changes to your code.
- "git remote add origin [email protected]:<your username>/<new repo name>.git" links your local Git repository to a remote repository on GitHub, named <new repo name>, owned by <your username>, allowing you to push and pull changes between the two.
git init && git remote add origin [email protected]:<your username>/<new repo name>.git
Create connection to GitHubStep 6: Now we have to view the public ssh key and copy it for further process.
cat ~/.ssh/id_rsa.pub
View Public KeyStep 7: Now after copying the public ssh key, head towards your github profile settings and click on the " ssh key " option. Click on "add" option and paste the copied ssh key. For more details on how to add ssh key to your profile, you can view the Github SSH Key Documentation.
Step 8: The next step is to test the connection, if its working or not. For this type the following command.
ssh -T [email protected]
Testing the connectionNow we are successfully authenticated to github. After this we can perform the pushing tasks.
Step 9: To push your code to the github, firstly move to the main branch. "git branch -M main" is a Git command that renames the current branch to main.
git branch -M main
move to the main branchStep 10: Now we are going to add the file that we have to push.
git add Testing
"Testing" is the file name for my code.
Add file for pushingStep 11: Now we will be pushing our file "testing" to the branch "main".
"git push --force origin main" is a Git command that pushes changes from your local repository to a remote repository (in this case, origin) and updates the main branch.
git push --force origin main
Pushing changes to main branchFinally, we are successfull pushing our code to the github.
Push Codes from Linux (UBUNTU) To GitHub using SSH KEY
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read