1. Generate key
$ ssh-keygen -t ed25519 -C "your@email.com"
# Generating public/private ed25519 key pair.
# Enter file in which to save the key (/home/user/.ssh/id_ed25519): [Press enter]
# Created directory '/home/user/.ssh'.
# Enter passphrase (empty for no passphrase): [Press enter]
# Enter same passphrase again: [Press enter]
# Your identification has been saved in /home/user/.ssh/id_ed25519.
# Your public key has been saved in /home/user/.ssh/id_ed25519.pub.
# The key fingerprint is:
# SHA256:9FypGi35JlcZ3O459VoyM4qTTCQTbTlIkohd3DNrMkU your@email.com
2. Copy key
# grab generated string
$ cat /home/user/.ssh/id_ed25519.pub
# ssh-ed25519 AAuZC3NzaC1lZDI1NTE5TzTAIOiGJohB9Doz4H0w6+GnrBdbOTwjRhN3CqYYurE5ZYPO your@email.com
3. Add that key to github.com repo
Go to GitHub.com ➤ Choose related repo ➤ Settings ➤ Deploy keys ➤ Add deploy key ➤ Save just generated key.
4. Prepare configuration file
Add next lines in /etc/ssh/ssh_config
file:
Host my_custom_git_host
Hostname github.com
User git
IdentityFile=/home/user/.ssh/id_ed25519
5. Test local key
ssh -T my_custom_git_host
If some error occurs, check by debugging it in verbose mode:
ssh -vT my_custom_git_host
If everything is ok, you should see smth. like this:
# Hi Organization/project! You've successfully authenticated, but GitHub does not provide shell access.
6. Finally test Push/Pull request
$ git remote add origin git@my_custom_git_host:organization/project.git
$ git push origin main
@source:
https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys