Git - Part 8: Connect to GitHub via SSH protocol

1. On your Windows machine I suggest installing Cmder console emulator, visit http://cmder.net/ and then download and install the Full package (with git-for-windows)

2. Open Cmder or other console software on your Windows machine, navigate to root directory, create .ssh directory and enter it

cd ~
mkdir .ssh
cd .ssh

3. Create SSH key pair id_rsa & id_rsa.pub (-t is type, -b is bytes, -f is filename)

ssh-keygen -t rsa -b 4096 -f id_rsa -C "email@domain.com"

When prompted for password, just hit Enter key - do not enter the password.

4. Display the public key on the screen, select the printed text and copy it to clipboard

cat id_rsa.pub

5. Open GitHub website (www.github.com) and login with your account

6. Navigate to Settings / SSH and GPG keys

7. Click "New SSH key" button on the top right corner

8. Enter title (can be anything you want), paste previously copied public key to the "Key" text area and click "Add SSH key"

9. Go back to Cmder (or any other console emulator) and enter

ssh -T git@github.com

10. Enter 'yes' when you get prompted with: Are you sure you want to continue connecting (yes/no)?

That's it. Now you do not have to enter your password every time when you push your code to GitHub.

Configure SSH to connect to a Remote Ubuntu Server

1. On your Windows machine I suggest installing Cmder console emulator, visit http://cmder.net/ and then download and install the Full package (with git-for-windows)

2. Open Cmder or other console software on your Windows machine, navigate to root directory, create .ssh directory and enter it

cd ~
mkdir .ssh
cd .ssh

3. Create SSH key pair id_rsa & id_rsa.pub (-t is type, -b is bytes, -f is filename)

ssh-keygen -t rsa -b 4096 -f id_rsa -C "email@domain.com"

4. Display the public key on the screen, select the printed text and copy it to clipboard

cat id_rsa.pub

5. Login to your Ubuntu Server and install OpenSSH in case you don't have it yet

sudo apt-get install openssh-server

Before you do that, don't forget to update the repositories with:

 sudo apt-get update

6. On your Ubuntu Server machine, navigate to root directory, create .ssh directory and enter it

cd ~
sudo mkdir .ssh
cd .ssh 

7. Create a file authorized_keys and open it for edit

touch authorized_keys 
nano authorized_keys 

6. Paste previously copied public key and paste it to this file

7. Logout from Ubuntu Server and try to login from your Windows machine

ssh username@192.168.1.100

(use your own Ubuntu Server root username & IP address)

8. If you're connecting to eg. GitHub via SSH, test your connection with this command:

ssh -T git@github.com

Copy public SSH key to your server

When you create SSH key pair on your computer, you can copy the public key to your server via terminal (console).

cat ~/.ssh/id_rsa.pub | ssh username@192.168.1.100 'cat >> .ssh/authorized_keys && echo "Key copied"'