How to use git on Ubuntu Server
You can use git to clone repositores e.g. from Github to the server.
- Generate ed25519 key on the server
Rename generated ssh keys to "githubkey"ssh-keygen -t ed25519 -C "user / device info"
Start SSH agent on backgroundmv ~/.ssh/id_ed25519 ~/.ssh/githubkey mv ~/.ssh/id_ed25519.pub ~/.ssh/githubkey.pub
Addeval "$(ssh-agent -s)"
githubkey
to SSH agentssh-add ~/.ssh/githubkey
- Go to your Github.com account settings. Within section "Access", select "SSH and GPT keys". Add new SSH key of type "authentication" with a content get from following command processed on teh ubuntu server:
cat ~/.ssh/githubkey.pub
- Create a custom configuration file for SSH on the Ubuntu Server
Fill the file with following configuration for github.com (or alternative services)nano ~/.ssh/config
Host github.com HostName github.com User git IdentityFile ~/.ssh/githubkey
- Check authentication to Git from Ubuntu Server
ssh -T git@github.com
You should get following response
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
- Download a git repository through its SSH address
git clone git@github.com:user/repository.git /path/to/clone
Connect to certain Git origin and push first commit
- Initialize git repository in PC
git init
- Create
README.md
file and add it to teh repositoryecho "# Repository" >> README.md
git add README.md
git commit -m "first commit"
- Set branch to
main
git branch -M main
- Set origin
git remote add origin <sshurl>.git
- Push first commit
git push -u origin main