Git is one of the most popular version control systems used by developers to manage source code. In modern workflows, Git is typically integrated with repository hosting services such as GitHub. For better security and convenience, GitHub requires the use of SSH keys for authentication, so you don’t need to enter your username and password every time you perform a push or pull.
1. Install Git on Ubuntu
First, update the system and install Git:
sudo apt update
sudo apt install git -yCheck the Git version:
git --versionExpected output example:
git version 2.43.02. Configure Git Identity
After installing Git, set your Git account identity globally on the system:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Check the configuration:
git config --list3. Generate a New SSH Key
Create an SSH key using the ed25519 algorithm (more modern and secure):
ssh-keygen -t ed25519 -C "[email protected]"When prompted for the storage location, press Enter to save it in the default path ~/.ssh/id_ed25519.
If you want to use a different name (e.g., for GitHub):
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_id_ed25519Start the ssh-agent:
eval "$(ssh-agent -s)"Add the key to the agent:
ssh-add ~/.ssh/github_id_ed255194. Add the SSH Key to GitHub
Copy the public key content:
cat ~/.ssh/github_id_ed25519.pubCopy the output, then open GitHub:
- Go to Settings → SSH and GPG keys → New SSH key
- Paste the key and give it a name (e.g.,
Ubuntu Laptop) - Click Add SSH key
5. Configure SSH Client
For convenience, you can create a configuration file:
nano ~/.ssh/configFill it with the following configuration:
# GitHub Account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_id_ed25519
IdentitiesOnly yesSave and exit (CTRL+O, CTRL+X).
6. Test SSH Connection
Test the connection to GitHub:
ssh -T [email protected]If successful, you will see a message like:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.7. Clone Repository Using SSH
You can now clone GitHub repositories using SSH without needing a password:
git clone [email protected]:username/repository-name.git8. Multi-Account GitHub Configuration with SSH Config
Sometimes you may have more than one GitHub account:
- A personal account for open-source projects
- A work account for professional use
To avoid confusion, you can create separate SSH keys and configure the ~/.ssh/config file so Git knows which key to use.
1. Generate SSH Keys for Each Account
Personal Account:
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_personalWork Account:
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/github_workAdd both keys to the ssh-agent:
ssh-add ~/.ssh/github_personal
ssh-add ~/.ssh/github_work2. Add SSH Keys to GitHub
- For the personal account → add
~/.ssh/github_personal.pubto your personal GitHub account - For the work account → add
~/.ssh/github_work.pubto your work GitHub account
3. Configure SSH Client
Open the configuration file:
nano ~/.ssh/configFill it with:
# Personal GitHub Account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/github_personal
IdentitiesOnly yes
# Work GitHub Account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/github_work
IdentitiesOnly yesWith this setup, you can use aliases like github-personal or github-work when cloning repositories.
4. Clone Repositories Based on Account
Clone a personal repository:
git clone git@github-personal:username/personal-repo.gitClone a work repository:
git clone git@github-work:org/work-repo.git5. Set Git User Configuration per Repository
To ensure commits use the correct identity, you can configure Git user settings per repository:
Enter the work repository directory and run:
git config user.name "Work Name"
git config user.email "[email protected]"For a personal repository:
git config user.name "Personal Name"
git config user.email "[email protected]"With this additional configuration, you can:
- Use multiple GitHub accounts on a single Ubuntu laptop/PC
- Assign different SSH keys per account
- Avoid identity conflicts when making commits
This ensures a clean and organized workflow for both personal and professional projects.




