Secure your SSH key with passphrase
- Generate your SSH key pair for the remote SSH servers:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/gitlab_rsa
Note: To secure your key pair, you must set a passphrase.
It will create two files: gitlab_rsa and gitlab_rsa.pub in ~/.ssh directory.
- Configure to use the key pair when connecting to the remote SSH server by adding following lines to ~/.ssh/config
Host gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab_rsa
Now if you rungit pull
for the gitlab repositories. It will ask for the passphrase for gitlab_rsa key.
Use ssh-agent
If you want to do ssh or git pull without entering passphrase. You can use ssh-agent:- Start ssh-agent:
eval $(ssh-agent -s)
- Add the private key:
ssh-add ~/.ssh/gitlab_rsa
You need enter the passphrase to add the key. - To list the keys managed by ssh-agent:
ssh-add -l
No comments:
Post a Comment