How to Set Up GitHub in a Local Environment on Ubuntu
Step 1: Install Git
Git is an essential tool for version control, allowing you to track changes to your code, collaborate with others, and maintain a history of your projects. On Ubuntu, installing Git is straightforward:
Update Your System:
- Before installing new software, it’s always a good idea to update your package list to get the latest version of the repository listings.
sudo apt update
Install Git:
- The following command will download and install Git.
sudo apt install git -y
Verify Installation:
- Confirm that Git was installed correctly by checking the version:
git --version
- This command should return the current Git version.
Step 2: Configure Git
After installing Git, set your user information. This information is tied to each commit, letting collaborators know who authored specific changes.
Set Your Git Username:
git config --global user.name "Your Name"
Set Your Git Email:
git config --global user.email "your.email@example.com"
- GitHub uses this email to associate your commits with your GitHub account, so make sure it matches the email on your GitHub profile if you want to link them.
View Your Git Configuration:
git config --list
- This will display your Git settings and confirm they’re saved.
Step 3: Generate SSH Keys
SSH (Secure Shell) keys allow you to securely connect to GitHub without needing to enter your password every time. GitHub uses SSH keys to authenticate your identity.
Generate a New SSH Key:
- Run the following command, replacing the email with the one you use for GitHub:
ssh-keygen -t ed25519 -C "your.email@example.com"
- When prompted, press
Enter
to save the key in the default location and add apassphrase
for extra security if desired.
What is SSH? SSH is a protocol that provides a secure way of accessing remote systems over a network. Using an SSH key pair (a private and a public key), you can securely connect your local machine with GitHub.
Step 4: Add SSH Key to the SSH Agent
The SSH agent manages your keys and helps you avoid re-entering your passphrase every time you use Git.
Start the SSH Agent:
eval "$(ssh-agent -s)"
Add Your Key to the Agent:
ssh-add ~/.ssh/id_ed25519
This command ensures your SSH key is loaded and ready for GitHub to use.
Step 5: Add Your SSH Key to GitHub
Now, you need to register your SSH key with GitHub to grant your machine access.
Copy Your Public SSH Key:
cat ~/.ssh/id_ed25519.pub
- Copy the output (your public key) to your clipboard.
Add the Key on GitHub:
Go to GitHub and sign in.
In the upper-right corner, click on your profile picture, and select Settings.
Go to SSH and GPG keys on the left sidebar and click New SSH key.
Paste your SSH key into the "Key" field, give it a recognizable name (e.g., “Ubuntu-24-laptop”), and click Add SSH key.
Step 6: Test Your SSH Connection
Once your key is added, test the SSH connection between your machine and GitHub.
Run the following command to test:
ssh -T git@github.com
If successful, you should see a message like:
Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
This message confirms your SSH key is working with GitHub.
Conclusion
Setting up GitHub on your local Ubuntu environment allows for easy code management, secure connections, and efficient collaboration. By installing Git, setting up SSH keys, and connecting your machine to GitHub, you can clone repositories, contribute to projects, and manage version control directly from your terminal. This setup lets you focus on coding while Git and GitHub take care of your project history and collaboration needs. Happy coding!
Subscribe to my newsletter
Read articles from Anik Kumar Nandi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Anik Kumar Nandi
Anik Kumar Nandi
Hi there! I'm Anik Kumar Nandi, passionate programmer, strongly focus on backend technologies. I specialize in PHP and Laravel, and I'm always exploring new ways to enhance the robustness and efficiency of my code. In addition to PHP and Laravel, my skill set includes RESTful API development, JavaScript, jQuery, Bootstrap, Ajax, and WordPress customization. Also deeply interested in AWS. Feel free to check out my GitHub profile and my portfolio site to learn more about my work and projects. Let's connect and create something amazing together!