Git is on the market in Ubuntu’s default bundle repositories on each 22.04 LTS and 24.04, so set up is quick. The extra concerned half is configuring SSH key authentication for GitHub or GitLab, which is what this information covers in full. You’ll additionally discover a part on managing a number of Git identities on a single server, which comes…
Conditions
- A Linux VPS or cloud server working Ubuntu 22.04 LTS or Ubuntu 24.04
- SSH entry with sudo privileges
- A GitHub or GitLab account (for the SSH key configuration steps)
Each Ubuntu 22.04 LTS and 24.04 ship with OpenSSH consumer pre-installed. No further instruments are required earlier than starting.
Not arrange on a VPS but? InMotion Internet hosting’s Cloud VPS contains Ubuntu 22.04 LTS as a supported OS. The Managed VPS helps Ubuntu throughout all plan tiers.
Step 1: Replace Bundle Lists
Earlier than putting in any bundle, sync your apt bundle index to make sure you’re pulling the newest accessible model.
sudo apt replace
Step 2: Set up Git
sudo apt set up git -y
The -y flag confirms the set up mechanically. On Ubuntu 22.04, this installs Git 2.34.x. On 24.04, you’ll get Git 2.43.x. To confirm the put in model:
git --model
Anticipated output will look just like: git model 2.43.0
Step 3: Configure Your Git Identification
Git requires a reputation and e mail tackle hooked up to each commit. Set these globally for the server consumer you’ll be working with.
git config --world consumer.title "Your Identify"
git config --world consumer.e mail "[email protected]"
Confirm the configuration:
git config --checklist
Step 4: Set Up SSH Key Authentication
Cloning and pushing to distant repositories over HTTPS requires a password or token on each operation. SSH keys authenticate as soon as and by no means immediate once more. That is the usual strategy for server-to-repository authentication.
4a. Generate the SSH key pair
ssh-keygen -t ed25519 -C "[email protected]"
The -t ed25519 flag specifies the Ed25519 algorithm, which is the trendy beneficial key sort. When prompted for a file location, press Enter to simply accept the default (~/.ssh/id_ed25519). Optionally set a passphrase.
In case your distant service requires RSA (older GitLab cases, for instance), use:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
4b. Show your public key
cat ~/.ssh/id_ed25519.pub
Copy the complete output, together with the ssh-ed25519 prefix and the remark on the finish.
4c. Add the important thing to GitHub or GitLab
On GitHub: Settings > SSH and GPG keys > New SSH key. Paste your public key and provides it a descriptive title (for instance, ‘InMotion VPS manufacturing’).
On GitLab: Person Settings > SSH Keys. Paste the important thing, give it a title, and set an expiration date in case your safety coverage requires one.
4d. Take a look at the connection
Anticipated output: Hello username! You’ve efficiently authenticated, however GitHub doesn’t present shell entry.
Anticipated output: Welcome to GitLab, @username!
Step 5: Clone a Repository
With SSH authentication configured, cloning makes use of the SSH URL fairly than HTTPS.
git clone [email protected]:yourusername/your-repo.git
The repository will clone right into a listing named after the repo. Navigate into it and ensure the distant configuration:
cd your-repo && git distant -v
Managing A number of Git Identities on One Server
Growth VPS environments regularly have to authenticate as completely different customers for various repositories. A developer account for private initiatives, a CI deploy key for a consumer’s repository, a separate identification for work. The SSH config file handles this cleanly.
Create a per-host SSH config
nano ~/.ssh/config
Add a block for every host identification:
Host github-private HostName github.com Person git IdentityFile ~/.ssh/id_ed25519Host github-consumer HostName github.com Person git IdentityFile ~/.ssh/id_ed25519_client
Generate the second key pair with a distinct filename:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_client -C "[email protected]"
Add id_ed25519_client.pub to the consumer’s GitHub or GitLab account beneath their deploy keys.
Use the alias when cloning
git clone git@github-consumer:clientorg/their-repo.git
SSH resolves github-client to github.com and makes use of the desired key file. This strategy works with none battle between identities, even on the identical bodily server.
Setting a Default Department Identify
Git’s default department title modified from ‘grasp’ to ‘fundamental’ in newer configurations, however repositories created on older setups should use ‘grasp’. To align your server’s Git conduct together with your crew’s conference, set the default department title globally:
git config --world init.defaultBranch fundamental
Non-compulsory: Set up a Newer Model through PPA
Ubuntu’s default repositories might not embody absolutely the newest Git launch. For those who want a more moderen model for particular options, the Git Maintainers PPA gives present builds for Ubuntu LTS releases:
sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt set up git
That is optionally available for many use circumstances. The model in Ubuntu’s default repos is secure and enough for the overwhelming majority of workflows.
Associated information: Learn how to Setup a VPS Server covers the complete VPS setup workflow from provisioning by means of deployment.
| Run Git on production-ready infrastructure. InMotion’s Cloud VPS contains Ubuntu 22.04 LTS with root SSH entry, high-availability structure, and no-nonsense pricing. See plans at inmotionhosting.com/cloud-vps. |









