Register the public key on Github

Register your public key on Github. If you register the public key, you can push / pull the Git repository with SSH protocol.

This article assumes that you are creating a private key on Linux.

Public and private key generation

First, change to the directory where you want to store the SSH private key. If the "~ / .ssh" directory does not exist, create it. The permission should be "700".

mkdir -p ~ / .ssh
chmod 700 ~ / .ssh
cd ~ / .ssh

To generate a public / private key pair, run the ssh-keygen command. The public key is a set with the private key, the private key is registered on the local machine, and the public key is registered on Github.

ssh-keygen -t rsa

You will be asked for the name of the file to be generated, so enter the following name.


The files "id_rsa_github" and "" will be created. "Id_rsa_github" is the private key and "" is the public key.

When you are asked to enter your passphrase, do not set a passphrase, so press Enter. Press Enter as you will be prompted to re-enter.

Private key permissions must be 600

The private key permission must be 600. If created using ssh-keygen, the permissions will be set to 600, but if you have copied the contents of the private key from another server, chmod command to set the permissions to 600.

chmod 600 id_rsa_github

Settings to use the private key created when connecting to Github via SSH

Let's set to use the private key created when connecting to Github by SSH. Add to "~ / .ssh / config". Let's also set the permission to 600.

Host github
  IdentityFile ~ / .ssh / id_rsa_github
  User git
'| cat >> ~ / .ssh / config
chmod 600 ~ / .ssh / config

Register the public key on Github

Register your public key on Github. Move from "Settings" of the user icon on the upper right.

Click SSH and GPG key.

Click New SSH key.

Enter the Title and Key. Title is optional and okay. Key is the content of "".

Let's display the contents of "" with the cat command.


It will be displayed as follows.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjSsucYA958wTIKUcPRXC2iZxb84FXkzm41 / jzpfnUeBFsypS8xfTXpfDaSIYeMDyr9pIUfDuWWPykoofL4WZaJYDy5pQclFwby / KttDRAnm0XZQ2ZDUtnrUUdva55mxOcTJP0c1VWXpwrhBA + JSFLOGB8wxCV8UFh9XWXI4c5QKQ / Hyl8 // nXT6suQf199VNf4Ru31rs + 49FDW9FyvoX1GGEEBJCT2ROVD6qi1xY766PuhM / 4OMQeIxZmZg8ysML307viqkKh / 2mecwkdV1mxGQt8GbO3gvTOX5h9p7tGEwa3zSHhxudux1Kf6Pfcg4FwKuld8r77DKMXEszpRI11 myapp @myhost

Let's paste this value.

Registration is now complete.

Confirm that you can connect to Github by SSH

Make sure you can SSH to Github.

ssh -T

If you haven't accessed the host yet, you'll be asked to allow communication, so type "yes" and press Enter.

It is successful when the following is displayed.

Hi shinshina-kimoto! You've successfully authenticated, but GitHub does not provide shell access.

Now you can push / pull with SSH.

Associated Information