Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 6.37 KB

Topic-04.md

File metadata and controls

70 lines (49 loc) · 6.37 KB

Part 1: The SSH protocol, key generation, configuration of user settings

The SSH protocol:

  • The SSH (Secure Shell) protocol is a network protocol that provides secure communication and remote administration capabilities over an unsecured network.
  • It allows users to securely connect to a remote server or device and execute commands, transfer files, and manage systems remotely.
  • SSH utilizes encryption and authentication mechanisms to ensure the confidentiality, integrity, and authenticity of the communication by running on top of the TCP protocol and always listens to the TCP/IP port number 22 by default, and it is secure since it encrypts the data using encryption algorithms like Advanced Encryption Standard AES or Data Encryption Standard DES.

In summary:

  • Designed for secure remote access and control of systems over an unsecured network.
  • Provides encrypted and secure communication between a client and a server.
  • Typically used for secure remote login, file transfers, and remote command execution.
  • Operates at the application layer of the network stack.

Establishing an SSH connection

There are three key steps:

  1. Verification of server: The client initiates the SSH connection and verifies the authenticity of the server by checking its public key.

  2. Generation of a session key: Once the server is verified, both the client and server negotiate a session key using the Diffie-Hellman algorithm. This session key is a shared symmetric key that will be used for encrypting and decrypting the data exchanged during the session.

image

  1. Authentication of the client: The client sends its public-private key pair identification to the server. The server checks its authorized_keys file to determine if the client's ID exists there. If a match is found, the server generates a random number and encrypts it using the client's public key. The client, possessing the correct private key, decrypts the message and retrieves the random number. Using this random number and the shared session key, the client and server generate an MD5 or SHA-2 hash. The client sends this hash to the server, which can independently calculate the hash using the shared session key and original random number. If the calculated hash on the server matches the one received from the client, the client is successfully authenticated, and the connection is established.

key generation:

  • Key generation in the context of the SSH protocol is a crucial step in establishing a secure and encrypted connection between the client and the server. It involves the generation of cryptographic keys that are used for encryption and decryption of the data transmitted during the SSH session. To generate an SSH key pair, you can use the ssh-keygen command-line tool. Once generated, you will have two files: id_rsa (private key) and id_rsa.pub (public key). the id_rsa.pub should be placed in the remote systems authorized_keys directory in its .ssh hidden folder on its home directory, this directory must also have root permissions granted. Now whoever has the corresponding private key can login to this remote computer using ssh protocol.

  • Here are the steps to explain how key generation and SSH connection establishment work between a Windows machine (client) and a Linux virtual machine (server):

  1. Key Pair Generation:
  • On the Windows machine, generate an SSH key pair using a tool like PuTTYgen.
  • This generates a public key (e.g., id_rsa.pub) and a private key (e.g., id_rsa) on the Windows machine.
  1. Server Configuration:
  • On the Linux virtual machine, ensure the SSH server (e.g., OpenSSH) is installed and running.
  • Copy the public key (id_rsa.pub) from the Windows machine to the Linux virtual machine.
  1. Server Authorization:
  • On the Linux virtual machine, add the copied public key to the authorized_keys file located in the ~/.ssh directory.
  • This allows the Linux virtual machine to authenticate the Windows machine's public key during SSH connections.
  1. Client Initiation:
  • On the Windows machine, use an SSH client like PuTTY to initiate an SSH connection to the Linux virtual machine.
  • Specify the IP address or hostname of the Linux virtual machine and the appropriate port (default is 22).
  1. Client Authentication:
  • During the initial connection, the Windows machine presents its public key to the Linux virtual machine.
  • The Linux virtual machine checks if the Windows machine's public key is in the authorized_keys file for authentication.
  1. Secure Communication:
  • If the Windows machine's public key is authenticated, the Linux virtual machine generates a session key and encrypts it using the Windows machine's public key.
  • The encrypted session key is sent back to the Windows machine.
  • The Windows machine decrypts the session key using its private key, establishing a shared session key for secure communication.
  1. Secure Shell Connection:
  • With the shared session key, the Windows machine and Linux virtual machine can securely exchange encrypted data during the SSH connection.
  • They can execute commands, transfer files, or perform any other supported SSH operations securely.

configuration of user settings:

  • SSH configuration file (ssh_config): Users can modify this global configuration file to set options that apply to all SSH connections from their account.

  • User-specific configuration file (~/.ssh/config): Users can create this file to override or supplement the global SSH configuration and define specific options for individual hosts or groups of hosts.

  • Authentication methods: Users can configure their preferred authentication method(s) (e.g., password-based, public key, certificate-based) for SSH connections.

  • Key-based authentication: Users can generate and configure SSH key pairs for more secure authentication, involving public-private key management and configuration.

  • SSH agent: Users can configure their SSH agent settings to securely manage and handle private keys for convenient, passphrase-protected key authentication.

  • Proxy settings: SSH can work through proxies like SOCKS or HTTP, and users can configure SSH to establish connections in restricted network environments.

  • Tunneling and port forwarding: Users can configure SSH to create encrypted tunnels for secure network connections and access remote services through port forwarding.