Add SSH keys without overriding id_rsa file. [gitlab]
Are you trying to add ssh keys but don’t want to override
id_rsa file? Well, you are at the right place. I will show you how to move ahead without overriding default keys. And also if you are facing some issue regarding connecting to gitlab via ssh on port 22 or if you are getting issue
Connection reset by peer, this blog will help you fix that issue too.
Steps to create keys.
ssh-keygen -t rsa -C "firstname.lastname@example.org" Enter file in which to save the key (/home/project/.ssh/id_rsa): [Type new file name. Don't override existing one. Eg. id_rsa_gitlab_key] Enter passphrase (empty for no passphrase): [No need to type password. Just press enter] Enter same passphrase again: [Press enter]
Once you are done, you will key detail as below.
The key's randomart image is: +--[ RSA 2048]----+ | o | | o . | | + | | + + | | S o . | | . = = o | | E * + o | | o.++ o | | *o.. | +-----------------+
If you see randomart image as shown in above, you have successfully created private and public keys. Now it’s time to connect these new keys. And only
git will know your key. If you escape this step, you will encounter with error
email@example.com: Permission denied (publickey). To fix this issue, just go through following steps.
- sudo nano ~/.ssh/config
- Now type following text in your ssh config file.
Host * AddKeysToAgent yes IdentityFile ~/.ssh/id_rsa_gitlab_key
That’s all. You have successfully connected your new gitlab keys. Now run
git pull command. You now be able to run it. Make sure you have used SSH url for your git project. You can check that by running
git remote -v command in your terminal. Your urls must start with
firstname.lastname@example.org to use
If you have issue while pushing your code and see
ssh_exchange_identification: read: Connection reset by peer. This means your server has block
outbound for port 22. Ask your admin to unblock port 22 on outbound. And the issue will be fixed. Don’t bother trying to change setting of ssh config file. Nothing will happen unless you admin unblocks outbound stuff.
Hope this is helpful. It took me 2-3 days to found out what was going on. I hope someone will find it easy by posting this blog. If so, please do share my blog.