$ implies command line command
> implies the outcome in the command line
Connecting Git and Github using SSH
The Secure Shell Protocol is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH applications are based on a client–server architecture, connecting an SSH client instance with an SSH server.
Now we are about to see how to connect your PC with Github (so that we can access our Github through our Git Bash in our Windows computer)
- Download Git Bash (https://git-scm.com/download/win).
- Open Git Bash.
- Enter command ls -al ~/.ssh to see if existing SSH keys are present.
(a list of files in your .ssh directory will be printed, if available)
- Check the directory listing for one of the following,
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
If they are not found or if you have an error running step 3, you do not have an existing SSH key pair. To create a new one follow the steps below.
- Either generate a new SSH key or upload an existing one.
If you don’t have or don’t wish to an existing key, generate a new one.
Or if you already have a key you desire listed, you can add that to Github.
- In Git Bash, use the command as below substituting your email address,
$ ssh-keygen -t ed25519 -C “your_email@example.com”
If you are using a legacy system which doesn’t support the ed25519 algorithm, use
$ ssh-keygen -t rsa -b 4096 -C “your_email@example.com"
This creates a new SSH key, using the provided email as a label.
> Generating public/private algorithm key pair.
- When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
> Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]
- At the prompt, type a secure passphrase.
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
Now we have a new SSH key.
Adding your SSH key to the ssh-agent
Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.
- Ensure the ssh-agent is running. To start it manually,
$ eval "$(ssh-agent -s)”
> Agent pid 59566
- Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519
Adding a new SSH key to your account
- Copy the Ssh public key to your clipboard.
$ clip < ~/.ssh/id_ed25519.pub
This command copies the contents of your file to the clipboard.
(Note: If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.)
- In the upper-right corner of Github page, click your profile photo, then click Settings.
- In the “Access” section of the sidebar, click SSH and GPG keys.
- Click New SSH key or Add SSH key.
- In the “Title” field, add a descriptive label for the new key.
- Select the type of key, either authentication or signing.
- Paste your key into the “Key” field.
- Click Add SSH key.
- If prompted, confirm access to your account on Github.
Testing SSH connection
- In Git Bash, enter this command,
$ ssh -T git@github.com
A warning might appear like this,
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
- Verify the RSA fingerprint you see matches Github’s public key fingerprint. If it does, then type yes. A successful message would look like this,
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.
As you have added your SSH key to your Github account, you can push, pull and do more Git commands through your CLI.
Comments
Post a Comment