Working with private Github repositories

In this article, you will be presented with instructions for working with Github.com private repositories on shared hosting.

Why with private repositories? It’s simple because when working with open (public) repositories, you do not need to take additional security steps, such as: generating SSH keys, SSH authorization in GitHub, generating a security token, etc.

Below is the instruction for you:

      1. Connect via ssh
      2. Run the command:
        ssh-keygen -t rsa -f ~/.ssh/sshkeygit -b 4096 -C "username@github.com"
        where:

        • sshkeygit – is the name of your key that is being generated. You can enter any name
        • username – is your username on github.com

         

        • Next, you are asked to enter a password for the key:
          Generating public/private rsa key pair.
          Enter passphrase (empty for no passphrase):
        • Next, you are asked to repeat the password for the key:
          Enter same passphrase again:
        • If everything is successful, you will see the following output:
          Your identification has been saved in /home/username/.ssh/sshkeygit.
          Your public key has been saved in /home/username/.ssh/sshkeygit.pub.
          The key fingerprint is:
          SHA256:3tC2vvn9e8xDIZnEDoZHfXguFtKX2ZCLD9gKeauHN68 username@github.com
          The key's randomart image is:
          +---[RSA 4096]----+
          |                      o.+ oo+|
          |                     . = B.*.|
          |                     .oo=.O. |
          |                    o.o +B.o |
          |                    Sooo.oo .|
          |                    . +o. .. |
          |                      .oo .o |
          |                    o.+. . .+|
          |                     oE*o .o=|
          +----[SHA256]-----+
        • Run the command:
          cat .ssh/sshkeygit.pub
        • And we get something like this:
          ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCkbQWMIkB0AGEvA6yw/5Yj2WEJ+RQVbOkVl2FVXQDvMDZl5RORJIOMYKACNhi2
          ...
          fcBARShsniGOnd/YTpKqAO3IjkbPewOnUf/DaePC6b8aDbngucJoxqbXZxMWueAFzaP+eyo6lzctrw== username@github.com
        • Copying the content
      3. Go to the Github.com site – log in to the site – go to Setting – then to the SSH and GPG keys section – in the SSH keys block, click on the New SSH key button – paste the content from step 2
      4. We return to the terminal and check the connection by running the command:
        ssh -i .ssh/sshkeygit -T git@github.com

        • We see the following message:
          The authenticity of host 'github.com (140.82.121.3)' can't be established.
          ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
          ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
          Are you sure you want to continue connecting (yes/no)?
        • We write “yes”, press Enter, and see the following message:
          Enter passphrase for key '.ssh/sshkeygit':
        • We write the password that was indicated in the first step. If everything is done correctly, you will see the following response:
          Hi username! You've successfully authenticated, but GitHub does not provide shell access.
        • This means that you are doing good and almost ready to work with GitHub. Why “almost”? Let’s figure it out in the next step.
      5. If you try to clone the repository by issuing the command:
        git clone https://github.com/username/blog.git

        • You will receive the following message:
          Клонирование в «blog»…
        • Next, you will be asked to enter a login and password from the Github site:
          Username for 'https://github.com':
          Password for 'https://username@github.com':
        • And instead of cloning the repository, you will see the following warning and error:
          remote: Support for password authentication was removed on August 13, 2021.
          remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
          fatal: Authentication failed for 'https://github.com/username/blog.git/'
      6. In order to clone the repository, go to the Github.com website in your account settings – then go to the Developer settings section – then to Personal access tokens and click on the Generate new token button. To create a token, fill in the following fields:
        • filling in the Note field
        • selection of the lifetime of the token Expiration
        • selection of the scope of the token Select scopes, for this instruction, the “repo” section will suffice
        • To create a token, click on the Generate token button

        In the “Personal access tokens” section, the created token will be visible: ghp_jo0VFGSoG002PxLXO7uDEg8juFW3JT48iZ9Q (this is not a working example)

        Copy it and go to the terminal.

      7. Now you can execute the clone command, but it will look like this:
        git clone https://<username>:<githubtoken>@github.com/<username>/<repositoryname>.git

        • and now, following the example, run the command:
          git clone https://git:ghp_jo0VFGSoG002PxLXO7uDEg8juFW3JT48iZ9Q@github.com/username/blog.git

          • note that https://<username> — username – must be git

           

        • and if you did everything correctly, you will get the following response:
          Клонирование в «blog»…
          remote: Enumerating objects: 3, done.
          remote: Counting objects: 100% (3/3), done.
          remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
          Получение объектов: 100% (3/3), готово.
Rate this article
Share this article
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
In this article