SSH Public and Private Keys

As we use services like GitHub, GitLab, BitBucket, Azure DevOps and etc, we are required to use SSH public/private key for authentication. SSH public and private keys can easily be created using ssh-keygen tool on your computer. You may need to install Git (Git Bash) if you use Windows as your client machine.

So ssh-keygen lets you generate private/public key pair on your machine. Here is how it looks like.

[amaterasu48@hogesvr ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/amaterasu48/.ssh/id_rsa): 
Created directory '/home/amaterasu48/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/amaterasu48/.ssh/id_rsa.
Your public key has been saved in /home/amaterasu48/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4Yuih+5+BowypaHOk/bp9mGXho24Kbyf/SaNZCF1upY amaterasu48@hogesvr
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|     . .         |
|    . o .        |
|. .. o . .       |
|.*  . + S        |
|* o .E+...       |
|=..+==+=.        |
| O.o@++o         |
|.=&%.o+.         |
+----[SHA256]-----+

When you execute ssh-keygen, it asks you to enter passphrase. You can enter it or choose not to enter it. It generates 2 files at ~/.ssh They are id_rsa.pub and id_rsa.

id_rsa.pub is the public key. The content of the file looks like the following.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsI1olqIE+PRQ0I5PhtyAHqWf0Z9ImXq3RbIclMi123um
5yi+/RyNULJsXURXj9I5F827YROxgbQCZurXciiBCz9q9Gfktf4gyjsPcm1zAavw30lSl48mNJ1
GkkbIP2kMYPbEZqhnLlTngzWq7ApAA6bkbqftVvpysoRMq7j43oAGHd+tLPZYgkwxK2jkA8IvEH
BM++tajmqWpOGJ2IKIU+38TfKBmtcUSVwTBtiJj3IVusdTrJtAi19puSA6Q/KonzERlDxwj6ddc
cnDhnuuaLNiOdrEYXBq1fS1oWd93usb2HvZm9AFHN8Nf9q0NUq/ZHKsDl0vOucl76rqP8Cpn 
amaterasu48@hogesvr

You usually paste the string to services like GitHub for authentication.

id_rsa is the private key which you never want to expose to anyone at all. The public key that you uploaded to a service like GitHub is used to encrypt data on the other end and your private key is used to decrypt the data. The private key that was generated in this example looks like the following. Don’t worry, I’ve already got rid of the sample private key from a machine where I generated the sample keys.

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA7CNaJaiBPj0UNCOT4bcgB6ln9GfSJl6t0WyHJTItdt7pucov
v0cjVCybF1EV4/SORfNu2ETsYG0Ambq13IogQs/avRn5LX+IMo7D3JtcwGr8N9JU
pePJjSdRpJGyD9pDGD2xGaoZy5U54M1quwKQAOm5G6n7Vb6crKETKu4+N6ABh3fr
Sz2WIJMMSto5APCLxBwTPvrWo5qlqThidiCiFPt/E3ygZrXFElcEwbYiY9yFbrHU
6ybQItfabkgOkPyqJ8xEZQ8cI+nXXHJw4Z7rmizYjnaxGFwatX0taFnfd7rG9h72
ZvQBRzfDX/atDVKv2RyrA5dLzrnJe+q6j/AqZwIDAQABAoIBAGvoC73Brq2+Q4k/
6MfwYtaddz+cYc/e3BcjPO6ma1gyrSOVXRRPcbl5WLXi+9nbW1hj0XdKp6m4pdma
FJjfFbbyPMbFI7TC3n4b9yzMYiobuX3Yw4269dNm8Ev/uBq+ZoKhTlin/nmli3lK
5Ubn+N4x78DQgGXCYN4SDSxFCnFn8A6EE72udb0BgLHL6daF8D0/ccPJO2SXD62G
vevamkk824hskQ3b50ksbR/B3JeziYuwxD9iJ4zdVky0lQcETxOUolvw0LtK+j3p
QsC08fv8Jz9e0wwQnmji9jPB2rYw03lY93rx4KTPHqLQ5sb7twLluR/NMxK65Bpp
uilhYMECgYEA+bL8MVUVf0Ljodjuus+93a5/hFrzj8hofmJw9Kk8bpjk6XzCJSbf
MRSGE8Wi2WNQ7cHu0QcAVdbgIbc4mIB0c5uIPtKU4OoY0atpdl+3X8MDc/FYKajw
v/3st4mNatWdp4NZ23M1rjSxNp29qojtYOvdSF+waH09xvinVqesWBkCgYEA8hjD
yP3DQqMV6SJzeuOMaXeB9vrGa6HD+4oD4tqHn5pj4yBr02lOPg5m7LWCroGwi0UA
bPa7BP2FskT4IISjg9u7Vl1H5ON7j9JyC/aJu6I/Wepgd0WJSTKT2nES+UzXY9Cf
9wz3Svrdx6fuutm4GxGFCROoW/wN9CzGRk3a5n8CgYBdocc9vHj+KpfvNch3VrUM
roV0nSJd1TmRwto2dEuL8VtNTpICmmvxHJAWU/L3720GasVhrm1qwtNy8SCQ1wJT
44uYeyCGomHCJbO7RrMdfqQJ0wNLQ+VbKR2dyT+1QvsGOJP2XWJQu8OEBmx7yTKy
OF/W5sLgu63xsYYWUXOn6QKBgQCofivlOxgmzLJ3K48LvEsBLDe72RU328I20vuZ
a1Zw8lcKwInK/cOC1Ss1G670HTbt9vww2heXhYsDY5T9rNLQ9qEPnqRm3RwmIOVX
BiMd//HvdnvlBvRhiV317jSyZZSS16Q9oTyLZsXsKyivys+jpzHb+151hpt/kZn9
XDo5qQKBgQDls2cPThaRJHY0K3wHV5GDKH7fGRaLH8FoRwIuEj55/ZKOIww8XANo
vUvVFmGawflW/DEcbNURZOndmnOtpCzOlyzfOBB/rbWy6DJNXhwqQpyt0NPt4yLt
nxu9sz7ja+NJ1yuq26yHonoFL6B5vKsBTLO+Tb2DIB74IBUdFeqXHg==
-----END RSA PRIVATE KEY-----

Once you generated your private/public key pair, go to your icon –> Setting –> SSH and GPG Keys in GitHub to add the public key to it and then you will be able to do git clone and other operations against GitHub.

I wanted to cover this basic so that I can move on to Jenkins installation and configuration on Azure.

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *