SSH Keys Generation and Authentication

Generate SSH Keys

Some systems such as source control repositories (GitLab, Bitbucker, GitHub, etc.) support SSH authetication. You can learn more about SSH Public Key Authentication and its advantages over traditional user-password authentication here.

The purpose of this post is to help you quickly generate a pair of SSH keys (public and private) with a linux console (or Git Bash for Windows).

By default, the private and public keys will have been created on $HOME/.ssh
Copy-paste the public key inside onto the server you want to authenticate your host with (e.g: GitLab under SSH keys section)

Every time you need to authenticate against the remote server your bash console will prompt you for credentials.

Change Passphrase

If you need to change your paraphrase your key won't change. Simply run the following command on your bash.

Remember Passphrase

Sometimes it is a bit annoying having to enter the passphrase each time we want to access the remote server for whatever read or write operation. A trick to make our life easier is to add a script that triggers when our session starts (e.g: when the git bash opens for first time), prompts for the passphrase and remembers it during the whole session.

To do so create a file called profile under your $HOME directory

Then create another file .profile also under $HOME directory.
This script will be automatically executed as soon as the user's bash session starts and it will execute the previous one. The passphrase will be asked only the first time.