If your Git pushes feel like begging for attention every time you type a password you are doing it wrong. Use SSH keys for GitLab to get secure, password free pushes and pulls. This guide walks through checking for existing keys generating a modern ed25519 key adding it to the SSH agent and registering the public key with GitLab while dropping a few snarky comments along the way.
First avoid trashing a key that already works for other servers. Peek inside your SSH folder to see what is already there.
ls -al ~/.ssh
Look for files like id_ed25519 and id_ed25519.pub or id_rsa and id_rsa.pub. If you find a pair you already use you can skip key generation and just add the private key to your agent later.
Use a modern algorithm and don't pick RSA unless you have a boring reason. Run this command and follow the prompts for file name and passphrase. A passphrase is optional but recommended for real security.
ssh-keygen -t ed25519 -C 'your.email@example.com'
The command will ask where to save the key. Press Enter to accept the default like ~/.ssh/id_ed25519 or give a descriptive file name if you want multiple keys for different machines. Remember the private key must stay secret. The public key is what you will paste into GitLab.
Typing your passphrase every time is fine if you enjoy suffering. The SSH agent caches the unlocked key so Git can do its thing without constant nagging.
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519
If the agent fails to start your system might already manage keys for you especially on macOS or some Linux desktop environments. If so just add the key with ssh add and move on.
Now grab the public key text. It is a single long line that starts with the key type and ends with your comment or email.
cat ~/.ssh/id_ed25519.pub
Copy the entire line and then open GitLab in your browser. Go to your user settings and find SSH Keys. Paste the key into the key field give it a useful title like Workstation or Laptop and save. You do not need admin rights to add personal keys to your account.
Make sure GitLab recognizes your shiny new key. Run this to test the connection and accept the host fingerprint when prompted.
ssh -T git@gitlab.com
A successful response will mention your GitLab username or a welcome message. If it complains about permission denied then something on the private key side needs fixing.
chmod 600 ~/.ssh/id_ed25519
.~/.ssh/config
would list a Host entry for gitlab.com and an IdentityFile pointing at the appropriate private key.That is all. You now have key based authentication for Git operations which eliminates password prompts and is more secure than typing credentials into the void. Go commit something meaningful or at least amusing.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.