author_profile_image

mariangela

Updated on September 20, 2024

Category:

Git

Tags:

Django

Git

GitHub

ssh key

resolv.conf

nameserver

8.8.8.8

github authentication token

GitHub installation in Ubuntu

How to install and log in to GitHub from the Ubuntu terminal

First things first, you need to create a GitHub account @ https://github.com/.

Open the Ubuntu terminal and run the following command to update/upgrade the existing packages

sudo apt-get update && sudo apt-get upgrade

and the following command to install GitHub

sudo apt install gh

In case of error, as in this case

01_apt_install_git_error

check that the resolv.conf file is in the /etc directory

cd /etc
ls -la
02_check_resolv_conf

If the file is missing, create it:

sudo nano resolv.conf
03_create_resolv_conf

Add the following entries to resolv.conf file:

nameserver 8.8.8.8 nameserver 8.8.4.4 04_add_nameserver_to_resolv_conf

To close the file, press Ctrl + x

then y

and finally press the Enter key.

Let’s try to install GitHub again. This time the installation should be successful.

sudo apt-get update && sudo apt-get upgrade
sudo apt install gh

Create an SSH key

 ssh-keygen -t rsa -b 4096
05_create_ssh_key

Create a config file in the ~/.ssh directory

cd .ssh
 sudo nano config

The command above has created and opened the config file. Add the following entries to the config file:

# GitHub:
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_github
User git

To close the file, press Ctrl + x

then y

and finally press the Enter key.

id_rsa_github is the name of the file where the ssh will be saved; you can call it whatever you like, e.g. id_rsa_github_your_username

Log in to GitHub from the Ubuntu terminal

The ssh key is added to your GitHub account at this point.

To log in, enter the following command:

 gh auth login
06_github_login

Create an authentication token at https://github.com/settings/tokens

Once you have the token, paste it in the Ubuntu terminal to complete the login process:

07_github_authentication_token