A quick tutorial showing you how to install and setup git on an Ubuntu server and pull a repo from Github.
What green means: any lines that you need to replace in this tutorial will be in green.
How to check if Git is installed on your Ubuntu server (or your current version):
If you get -bash: git: command not found, then git is not installed
How to install Git on Ubuntu:
It’s very easy using apt-get. The program installs everything you need in one command.
sudo apt-get install git
You will be asked if you want to continue. Press ‘y’
After it finishes downloading it is ready to go.
How to setup Git:
After Git is installed you will need to enter your username and email
git config --global user.name "Your Name" git config --global user.email email@example.com
How to Generate an SSH key:
1. First check to see if there exists and .ssh directory
If there is no directory you will see: “No such file or directory”
2. If the directory exists and a key exists backup and remove SSH Key
ls# Lists all the subdirectories in the current directory # config id_rsa id_rsa.pub known_hosts mkdir key_backup# Makes a subdirectory called "key_backup" in the current directory cp id_rsa* key_backup# Copies the id_rsa keypair into key_backup rm id_rsa*# Deletes the id_rsa keypair
3. Generate a new SSH Key
# Creates a new ssh key using the provided email ssh-keygen -t rsa -C "firstname.lastname@example.org" # Generating public/private rsa key pair. # Enter file in which to save the key (/home/you/.ssh/id_rsa):
Next enter a passphrase (or leave it blank) – You will use your passphrase every time you do a Git pull or push. If you leave it blank then it won’t ask you for one.
Now you should see something like this.
Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db email@example.com
How to add your SSH Key to Github:
Copy the contents of the file id_rsa.pub
It’s important to copy the full key with no extra spaces or missing characters.
Next go to your Github account settings
Click on the “SSH KEYS” menu item on the left
Then click “Add SSH key”
Paste the key into the key field and click “Add Key”
You will be asked for you password. Enter it.
How to test if your SSH key is added:
ssh -T firstname.lastname@example.org
You will see the following warning
The authenticity of host 'github.com (184.108.40.206)' can't be established. # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. # Are you sure you want to continue connecting (yes/no)?
If SSH key was properly added to Github you will see
Hi Username! You’ve successfully authenticated, but GitHub does not provide shell access.
How to clone your Github repo into your Ubuntu server:
cd into the directory that you want to clone your repo
Next go to your respository hosted on Github
You will see a text field that has the SSH git clone info. Copy that.
Now in your terminal type git clone and then paste the above text field after (as seen below)
git clone email@example.com:Username/gitrepo.git
You should now see the git repo in your server
If you get an error like this “git fatal: could not create work tree dir” this means your Ubuntu user does not have permission to create files in the current directory. There is an easy way to give your user permission to edit and create files in a directory owned by another user.