Code

SSH: What it is, how to set it up, and how to use it

SSH: What it is, how to set it up, and how to use it

Course with employment: "Web Developer"

Learn More

After registering with GitHub, users receive a profile with a configured HTTPS connection. This protocol ensures secure uploading and downloading of data from remote repositories. However, some companies prefer to use an alternative—the SSH protocol. This may be due to various factors, such as security, ease of access management, and process automation. The SSH protocol provides additional features for working with repositories, including easier authentication setup and access key management. Therefore, developers working in such companies may consider switching to SSH to improve their GitHub experience.

In this article, we will take a detailed look at the SSH connection and the process of reconfiguring your GitHub profile to work with it. We will first discuss the theoretical foundations explaining how this technology works. You'll learn how data is transferred between your devices and remote servers, and gain an understanding of the security aspects of this process. Understanding these aspects will help you effectively use SSH to manage your GitHub repositories.

If you're just starting out with Git, we highly recommend learning the basics of GitHub before setting up an SSH connection. Understanding the platform's functionality will help you manage your repositories and projects more effectively. GitHub offers many collaboration features, so it's important to master its interface and basic commands.

In this article, you'll learn key aspects that will help you better understand the topic. We'll cover the fundamental principles, current trends, and practical recommendations so you can apply the knowledge you've gained effectively. Discover important facts and tips that will help you deepen your knowledge and skills in this area. Immerse yourself in the world of information and discover new horizons for your own development.

  • What is the SSH protocol;
  • How it works;
  • How to create private and public keys for SSH encryption;
  • How to set up an SSH connection on GitHub.

An expert is a specialist with deep knowledge and skills in a specific field. Experts play a key role in the development of various industries, providing valuable recommendations and solutions. Their experience allows them to analyze complex situations and propose effective strategies. Experts often participate in scientific research, consulting, and training, contributing to the dissemination of knowledge and the development of skills of other specialists. Having an expert on the team significantly increases the chances of project success and the implementation of innovative ideas. It is important to consider their opinion when making decisions, as it can significantly impact the final result.

CTO at Flocktory, Program Director of the DevOps Engineer program at Skillbox, and Director of the DevOpsConf conference program committee. Specializes in the implementation of modern technologies and methodologies in DevOps, which optimizes software development and delivery processes. Has extensive experience in managing teams and projects, as well as training and mentoring new DevOps professionals.

What is SSH and why was it created?

Before the introduction of SSH, the Telnet protocol, known as the Teletype Network, was widely used for remote connections. This protocol provided the ability to execute terminal commands, transfer files, and update data, which made it possible to effectively solve many system administration tasks. However, Telnet had serious vulnerabilities because it transmitted data in cleartext and did not provide protection against traffic interception. This is because the protocol was developed in 1969, when network scalability was a priority for engineers, not security. As a result, Telnet became a vulnerable tool, making it less suitable for modern IT security requirements. SSH, which appeared later, significantly improved the level of protection, providing data encryption and user authentication.

Read also:

The Internet is a global network connecting millions of computers and devices around the world. It was created in the 1960s as a research project but became available to a wider audience in the 1990s. It is important to understand that the Internet and the World Wide Web (WWW) are not the same thing.

The Internet is an infrastructure that transmits data using protocols such as TCP/IP. It is a network of servers, routers, and other devices that facilitate the exchange of information. The World Wide Web, in turn, is a system of interconnected hypertext documents accessible through browsers.

Thus, the Internet is the foundation upon which the WWW functions. The Internet enables the exchange of data, while the World Wide Web is the interface that makes this data available to users. Understanding these differences is essential for the effective use of network resources and the development of web content.

Learning about the internet and its structure will help you better navigate the digital world and harness its potential for business and personal needs.

Let's look at the vulnerability of open data transmission using specific examples. When a user sends an unencrypted file via Telnet, there is a risk that an attacker intercepting network traffic will be able to access the file's contents. Such data, transmitted in cleartext, can be easily compromised, emphasizing the importance of using secure protocols for information transfer. Protecting data from unauthorized access should be a priority for every user and organization to prevent leaks and loss of confidential information.

The user has the option of encrypting the file before sending it via Telnet. However, if the sender and recipient do not meet in person, the decryption key must be sent over the network. This creates the risk that an attacker could obtain both the file and the key to it, which compromises data security.

Scheme of open data transfer via Telnet protocol Illustration: Olya Ezhak for Skillbox Media

SSH, or Secure Shell, replaced the legacy Telnet protocol. It is a modern application-layer protocol that enables secure remote data exchange between devices. SSH is based on the use of a private and public key pair, which allows for the protection of transmitted information using asymmetric encryption algorithms. Thanks to this, SSH provides a high level of security and data confidentiality, making it the preferred choice for administrators and users seeking to protect their connections from unauthorized access.

Imagine a situation in which the first user wants to retrieve a file from a second user. They use a key and an open lock. The key remains with the first user, and the open lock is transmitted over the network. The lock reaches the recipient, but falls into the hands of an intruder. As a result, the file containing the data is still not transferred. This situation illustrates the importance of data protection and authentication in digital interactions. Without the proper level of security, even the transfer of information may be vulnerable to unauthorized access.

Secure data transfer scheme via SSH protocol. Part 1 Illustration: Olya Ezhak for Skillbox Media

The second user locks the file and sends it back. The closed lock is returned to the first user and the attacker. The first user opens the lock with their key and retrieves the file. The attacker has both the open and closed locks, but without the key, they cannot access the file. Thus, the parties can securely exchange data, ensuring the protection of information from unauthorized access.

Secure data transfer scheme via the SSH protocol. Part 2 Illustration: Olya Ezhak for Skillbox Media

In the SSH concept, an open lock symbolizes a public key, also known as a public key. The key to the lock represents a private key. The public key is used to encrypt data, while the private key is used to decrypt it. Without the private key, even the rightful owner of the data cannot access it. Therefore, protecting the private key is a critical task.

Implementation of the SSH protocol in the context of client-server interaction Illustration: Olya Ezhak for Skillbox Media

The implementation of the SSH protocol is carried out through several key stages. This mechanism includes establishing a secure connection, the authentication process, and the subsequent exchange of data between the client and the server. Each of these stages plays an important role in ensuring the security of information transfer and protecting against unauthorized access. Using SSH, users can securely manage remote systems, transfer files, and execute commands, making the protocol an indispensable tool for administrators and developers.

  • The client sends its public key ID to the server. In this way, it declares that it possesses the corresponding private key.
  • The server encrypts a random message with the public key and sends it to the client. The client must decrypt this message and send it back.
  • To verify authentication, the client must decrypt the message and transmit it in encrypted form back to the server. This proves that it really does possess the private key. Otherwise, the request will be rejected.
  • The client and server agree on a shared secret key. The Diffie-Hellman cryptographic protocol ensures secure key negotiation.
  • The parties choose the traffic encryption method. Currently, AES-256, AES-192, and AES-128 are commonly used—the choice depends on the agreement of the parties and the server's security settings. However, security algorithms are periodically updated, so it is important to focus on a modern standard.

After successful authentication, the client and server establish a secure encrypted channel for data exchange. This guarantees protection of information from unauthorized access and ensures the confidentiality of data transmission. Secure data exchange is a key aspect of modern web technologies, ensuring the protection of users' personal information and the integrity of interactions between the client and server.

Implementation of the SSH protocol in the context of client-server interaction: expert version Image: Maya Malgina for Skillbox Media

How the SSH Encryption Algorithm Works

SSH uses the RSA algorithm by default, which is a mathematical model for encrypting and decrypting data using a pair of keys. This algorithm is based on the principle of asymmetric encryption, where one key is used for encryption and the other for decryption. The encryption process is carried out using a function that transforms the original data, while the inverse function is responsible for restoring the original text from the encrypted information. Using RSA in SSH provides a high level of security and data protection during transmission.

To deeply understand how the inverse function works, it is important to consider an example of complementary color matching on the Itten circle. In a color wheel, each color has its own complementary color, which is located on the opposite side of the circle and is separated from the main color by a neutral white zone. Bright examples of complementary pairs include red and green, yellow and violet, and orange and blue. Understanding these color relationships helps in creating harmonious color combinations in design.

Scheme of complementary color selection on the Itten circle Illustration: Skillbox Media

Users They decided to exchange colors. The first participant chooses a primary color and determines its complementary color, as well as the mixing mechanism. The complementary color is transmitted to both the correct recipient and the attacker. The attacker, however, has no knowledge of the chosen primary color. This process of color exchange involves interesting interactions and strategies that can be used to create unique color combinations.

Scheme of the SSH encryption algorithm using color and inverse color as an example. Part 1Illustration: Olya Ezhak for Skillbox Media

The second user combines an additional color with the one he intended to send in response. As a result, a new color is formed, which reaches the addressee and falls into the hands of the attacker.

Scheme of the SSH encryption algorithm using color and inverse color as an example. Part 2 Illustration: Olya Ezhak for Skillbox Media

The first user mixes their original color with the resulting color, resulting in the color submitted by the second user. The attacker, possessing the complementary color from the first user and the resulting color from the second, attempts to mix these colors. However, as a result, they will be unable to determine the intended color. This highlights the importance of security and privacy in the color transfer and mixing processes, as the attacker does not receive the necessary information for decryption.

SSH encryption algorithm diagram using color and reverse color as an example: part 3 Illustration: Olya Ezhak for Skillbox Media

Encryption algorithms employ processes similar to color matching, but instead operate on data. The private key is never stored on the server, while the public key can be freely transmitted over the network. If an attacker intercepts the public key, they will not be able to use it to access encrypted information. The only remaining attack method is to randomly guess a private SSH key. However, the probability of a successful guess is extremely low, since keys are long sequences of randomly generated characters. Examples illustrating this process will be provided below.

Besides RSA, there are many other algorithms used to generate digital keys. Among them are DSA (Digital Signature Algorithm), ECDSA (Elliptic Curve Digital Signature Algorithm), and ElGamal. These algorithms provide varying levels of security and performance, making them suitable for a variety of cryptographic tasks. The choice of algorithm for generating digital keys depends on security requirements and data processing speed. The use of these technologies in electronic signatures and information encryption helps protect data and authenticate users.

In 2024, RSA and Ed25519 remain the most popular digital signature algorithms. These algorithms provide a high level of security and are widely used in various fields, including cryptography and data protection. Ed25519, being part of the EdDSA family, offers significant advantages in performance and reliability compared to traditional methods such as DSA. RSA, despite its age, continues to be the standard for many applications due to its proven reliability. The choice between these algorithms depends on the specific tasks and security requirements.

Let's look at the differences between the RSA and Ed25519 algorithms. RSA is compatible with all operating systems, but requires significant resources, including memory and processor time, to generate and verify keys. In contrast, Ed25519 demonstrates high efficiency and lower resource requirements, but its compatibility is not limited to all systems.

Most users do not distinguish between the RSA and Ed25519 algorithms, but to ensure the reliability and security of data, it is recommended to use RSA with a key length of 3072 or 4096 bits. This will provide a high level of protection and resistance to modern threats. RSA remains one of the most common encryption algorithms, and its use with a sufficient key length guarantees reliable information protection.

How to create encryption keys

If you are using Linux or macOS, open the terminal. If you have Windows 10 or newer, configure OpenSSH. For older versions of Windows, it is recommended to use PuTTY Generator or similar SSH utilities.

To generate SSH keys, open a terminal and enter the ssh-keygen command. The system will generate a key pair and prompt you to specify a location to save them; by default, this is your home directory. The generated keys will be placed in the .ssh folder and named id_rsa. Using SSH keys ensures the security of your connections and simplifies the authentication process when working with remote servers.

You can change the SSH key name and its storage location by overwriting the path suggested by the system. For example, instead of the standard path /Users/macbook/.ssh/id_rsa, you can use /Users/macbook/.ssh/myKey. However, keep in mind that overwriting the existing private key will delete it and replace it with a new key with the changed name. This will result in loss of access to servers where the old key was used. Therefore, it is recommended to change the key name only if you are deleting an unused key.

To protect an existing SSH key from being overwritten, it is recommended to use the -f flag when running the ssh-keygen command. Example command: ssh-keygen -f $HOME/.ssh/skillbox_private. In this case, the system will prompt you for a password to encrypt the private key and store it securely. The skillbox_private and skillbox_private.pub keys will be created in the .ssh directory, after which the system will notify you of the completion of the operation. You can then use the new keys to securely access the servers.

The next step is to create a passphrase, which serves as an additional security measure. Although creating one is optional, you can skip this step by pressing Enter. After this, all the keys will be ready, and the terminal will display a graphic with the name of the encryption technology used.

Generate keys, skip the passphrase and select the proposed directory Screenshot: iTerm2 / Skillbox Media

To view the contents of the .ssh folder, you need to run a series of commands. This folder typically contains SSH keys used for secure access to remote servers. To get started, open a terminal and run the command ls -la ~/.ssh . This command will display all files and directories in the .ssh folder, including hidden ones. If you're looking for specific keys or configuration files, pay attention to the .pub files, which represent public keys, and the config file, which contains connection settings. Checking the contents of the .ssh folder is important for managing SSH keys and ensuring the security of your connections.

  • cd .ssh — navigate to .ssh folders;
  • ls -a — list contents, including hidden files;
  • cat id_rsa — view the contents of the private key.

Reading is an important part of our lives. It not only develops thinking and imagination but also enriches vocabulary. Books, articles, and other sources of information can help expand horizons and deepen knowledge in various fields. If you are looking for reading inspiration, consider contemporary works, classic literature, and scientific articles. Each genre offers a unique perspective and can be a source of new ideas. Remember that regular reading helps improve concentration and analytical skills, which is useful both in your personal and professional life.

Basic Terminal Commands and Keyboard Shortcuts in Linux, Unix, macOS, and FreeBSD

The terminal is an essential tool for users of Linux, Unix, macOS, and FreeBSD-based systems. Knowing basic commands and keyboard shortcuts allows you to interact effectively with the system, speeding up tasks and streamlining your workflow.

Terminal commands allow you to perform a variety of operations, such as navigating the file system, managing files and folders, installing software, and performing system administration tasks. Basic commands include ls to list files, cd to change directories, cp to copy files, mv to move and rename, and rm to delete.

Terminal keyboard shortcuts also play an important role in improving productivity. For example, keyboard shortcuts such as Ctrl+C to interrupt a running command and Ctrl+Z to pause a process are essential tools for task management. Using the Tab key to autocomplete commands and paths greatly simplifies typing.

Knowing these commands and keyboard shortcuts helps users use the terminal more efficiently, which is especially important for system administrators and developers. A deeper understanding of the command line opens new possibilities for task automation and system management.

Note: The private key shown in the screenshot is for example purposes only. This key is not in use and has been removed. Do not share this key with third parties, as it is critical to the security of your information.

A fragment of a private SSH key: a set of unrelated characters that are difficult to guess. Screenshot: iTerm2 / Skillbox Media

The cat id_rsa.pub command allows you to view the public key, which is a unique set of characters. This key can be shared with other users or systems to establish a secure connection. The public key is used in cryptographic protocols for authentication and data encryption, ensuring secure information transfer.

Example of a public SSH key Screenshot: iTerm2 / Skillbox Media

Creating SSH keys is an important step in ensuring the security of connections. In most cases, the basic scenario is used, but in some situations, you may need to specify the encryption technology and key size. To do this, use the command: ssh-keygen -t {encryption technology} -b {key size in bits}. Specifying a specific encryption technology and an appropriate key size improves the protection of your data and enhances the security of your connections.

After the -t parameter, specify the desired technology, and after -b, the key size to be set. Then we continue according to the standard algorithm: select a folder to save the keys and, if required, enter a passphrase for additional security.

Example of a specific SSH key: change the rsa encryption technology to ed25519 and increase the key size from 3072 to 4096 bitsScreenshot: iTerm2 / Skillbox Media

The .ssh directory allows you to securely store various SSH keys. This allows you to effectively manage access to remote servers and secure connections. Storing keys in .ssh simplifies the authentication process and increases security when working with the SSH protocol. Make sure the permissions for this directory are configured correctly to prevent unauthorized access to your keys.

Example of SSH keys generated by a specific request Screenshot: iTerm2 / Skillbox Media

How to set up SSH on GitHub

To connect to GitHub from the terminal, enter the command ssh git@github.com. If you are connecting to GitHub for the first time, the terminal will prompt you to add this site to the list of trusted hosts. You will then receive a message indicating whether or not SSH keys are available. At this stage, public keys will not be available, and you will need to create and configure them for further work with repositories on GitHub.

Add github.com to the list of trusted hosts and make sure there are no public keys Screenshot: iTerm2 / Skillbox To use GitHub, visit github.com and follow the steps below. First, create an account if you don't have one. Then log in using your credentials. You can then create a new repository or clone an existing one. To create a repository, click the "New" button and follow the instructions to fill in the required fields, such as the project name and description. To clone a repository, copy the URL and use the git clone command in the terminal. After completing these steps, you can start working with your project on GitHub.
  • Create an account if you don't have one;
  • In your profile settings, select the "SSH and GPG keys" subsection;
  • Click the "New SSH key" button and paste the public key into the field;
  • Add a short, arbitrary description to the public key;
  • Click "Add SSH key" and enter the account password, if necessary.

Public keys do not require a detailed description. This is especially convenient if you have several keys for different projects. Having descriptions allows you to quickly find the key you need, which greatly simplifies the management and organization of your cryptographic keys.

Add a public SSH key and name it myKeyScreenshot: GitHub / Skillbox Media

Enter the command ssh git@github.com in the terminal. If your public key has been successfully added to your GitHub settings, the platform will recognize you and greet you by the name specified in your profile.

Authentication completed, GitHub sees our profile. Screenshot: iTerm2 / Skillbox Media

After adding a public key, you can interact with remote repositories via SSH instead of HTTPS. This eliminates the need to constantly enter your username and password, significantly simplifying and speeding up the process of working with GitHub. Using SSH keys increases security and convenience, allowing you to focus on development without unnecessary barriers.

Authentication completed, GitHub sees our profile. Screenshot: GitHub / Skillbox Media

If you have any questions or difficulties during setup, or would like to deepen your knowledge of SSH, we recommend checking out the documentation on GitHub. It contains useful information and guides to help you better understand and use SSH.

GitHub and a number of other services do not support password authentication. However, a password is still required to connect remotely to the server, but it can be replaced with a more secure method – SSH. Using SSH keys not only simplifies the connection process but also increases security, as it eliminates the possibility of password interception. Setting up SSH allows users to securely manage their repositories and execute commands on remote servers, making it the preferred method for developers and system administrators.

To set up an SSH connection, start by connecting to your server for the first time, specifying your username and password. After successful authorization, run the command ssh-copy-id user@host and re-enter your password. This will allow you to set up SSH keys, simplifying future connections to the server without having to enter a password each time.

  • ssh — request to establish a secure connection;
  • user — enter the provided login;
  • host — the address of the remote server. This can be either an IP address or a host with a specific domain name.

The SSH connection has been successfully established, allowing you to log in to the specified server without having to enter a password. This will provide more convenient and secure access to the remote system, allowing you to automate various processes and manage the server with minimal effort. Make sure all necessary security measures are in place to protect your server.

Learn more about the world of programming and code in our Telegram channel. Subscribe to stay up to date with interesting content and helpful tips!

Check out the following:

  • GitLab: What It Is and How to Use It"
  • "Silly Questions About Git and Version Control Systems"
  • "What is GitHub and How to Use It"