How to set up SSH keys on Ubuntu 22.04

Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.
Search for a command to run...

Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.
No comments yet. Be the first to comment.
Overview To work faster with VSCode, configure global snippets which will be available for all languages. Installation File -> Preferences -> Configure User Snippets -> New Global Snippets File -> FileNameYouChoose -> Enter In the opened file, enter...
The git log command is used to view the commit history of a Git repository. You can customize the output format to show specific details in a more readable or structured way. Below are some useful variations and formatting options for git log: To sh...

Overview This article will teach us how to: Install Ubuntu Server 24.04 on a laptop from scratch Install Ubuntu server by using Vagrant tool with ISO image Prerequisites: A laptop without any OS installed; A virtualization software Virtualbox t...

The /etc/passwd and /etc/shadow files are the backbone of Linux user management. Together, they store user account information and handle authentication securely. This article provides a hands-on guide to understanding these files, their structure, a...

In Linux, links are powerful tools that allow you to create references to files and directories. There are two main types of links: hard links and soft links (also known as symbolic links or symlinks). Understanding the differences between these two ...

A hostname is a human-friendly name given to a computer. It is a unique identifier that allows us to identify the machine in various network communications, making it easier to locate and manage devices. Type: hostname To see where it is stored, typ...

The Secure Shell protocol (SSH) is used to create secure connections between your device and GitHub Cloud. SSH uses two keys, a public key and a private key.
The public key can be distributed.
The private key should be protected.
The connection is authenticated using public SSH keys, which are derived from a private SSH key (also known as a private/public key pair). The secure (encrypted) connection is used to securely transmit your source code between your local device and GitHub Cloud.
Git is a distributed version control system, which means you can work locally, and then share or push your changes to a server. In this case, the server you push to is GitHub.
GitHub uses the SSH protocol to securely communicate with Git. When you use SSH keys to authenticate to the GitHub remote server, you don’t need to supply your username and password each time.
To use SSH to communicate with GitHub, you need:
The OpenSSH client, which comes pre-installed on GNU/Linux, macOS, and Windows 10.
SSH version 6.5 or later. Earlier versions used an MD5 signature, which is not secure.
In this hands-on lab, I will create an AWS EC2 instance using AWS SDK. I will manually configure the default Security Group by adding a new inbound rule to allow incoming SSH traffic from my custom IP. Then, I will generate a new key pair on this EC2 instance and push the public key onto my GitHub account. Finally, I will connect to EC2 to verify the connection.
To set up your device for connecting to GitHub Cloud using SSH, you need to:
View the version of SSH installed on your system, run ssh -V:

See if you have an existing SSH key pair:
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key. By default, the filenames of supported public keys for GitHub are one of the following.
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub

Generate a new SSH key. Paste the text below, replacing the email used in the example with your GitHub email address:
ssh-keygen -t ed25519 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ALGORITHM with your custom key name.
At the prompt, type a secure passphrase:
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

Start the ssh-agent in the background:
$ eval "$(ssh-agent -s)"

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

Add the SSH public key to your account on GitHub. Copy the contents of your public key file. You can do this manually or use a script:
cat ~/.ssh/id_ed25519.pub

xclip to copy an ED25519 key to the clipboard: sudo apt update and sudo apt-get -y install xclipVerify that you can connect by running this command:
ssh -T git@github.com
