The passphrase stored in
ssh-agent is invalidated when the git client machine is rebooted.
1. Make a key pair for GitHub/GitLab
Make a new key pair with
ssh-keygen. You can use
ssh-keygen -t ecdsa, or
ssh-keygen -t ed25519 for more security. In GitLab,
ssh-keygen -t ed25519 is acceptable on GitLab 10.3 or later.
$ ssh-keygen -t rsa
For convenience, make a new public/public key pair (
~/.ssh/id_rsa_nopassphrase) without passphrase.
Generating public/private rsa key pair. Enter file in which to save the key (/home/yourname/.ssh/id_rsa): /home/yourname/.ssh/id_rsa_nopassphrase
For passphrase prompt, just type enter twice (no passphrase).
Enter passphrase (empty for no passphrase): Enter same passphrase again:
ssh-keygen will make a new key pair.
Your identification has been saved in /home/yourname/.ssh/id_rsa_nopassphrase. Your public key has been saved in /home/yourname/.ssh/id_rsa_nopassphrase.pub. The key fingerprint is: SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX yourname@Hostname The key's randomart image is: +---[RSA 2048]----+ | | | | | | | | | | | | | | | | | | +----[SHA256]-----+
2. Set the new public key to GitHub/GitLab
Open the new public key (
~/.ssh/id_rsa_nopassphrase.pub) and copy&paste the content.
- If you use GitLab, Open 'SSH Keys' tab in 'Profile Settings', and paste the key in the 'Key' section.
- If you use GitHub, Open 'SSH and GPG keys' tab in 'Settings', push 'New SSH key', and paste the key in the 'Key' section.
3. Make git to use the new private key
~/.ssh/config file if it isn't exist. add the content below to the
This setting makes git to use the new private key for ssh connection.
Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_nopassphrase Port 22
4. Test the connection to GitHub/GitLab
$ ssh -T firstname.lastname@example.org Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
If any error occurred, try
ssh -Tv email@example.com, and see the messages.
5. Try git command
Note that use the username
git (not your account name in GitHub/GitLab) in comnand.
$ git clone --depth 1 firstname.lastname@example.org:yourname/repository.git $ cd repository/ $ git push Everything up-to-date