SSH Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

SSH (Secure Shell)

SSH is a cryptographic network protocol that allows secure communication over an


unsecured network. It is widely used for secure remote access to systems, file
transfers, and tunneling applications. SSH encrypts the communication between a
client and a server, providing confidentiality and integrity.

SSH Key Pair:


SSH authentication involves the use of key pairs, consisting of a private key and a
public key. Here's a detailed explanation of each component:

1. Private Key:

o The private key is kept on the user's local machine and must be kept
secret. It is used to decrypt messages that were encrypted with the
corresponding public key. If someone gains access to your private key,
they could impersonate you.

Example: id_rsa is a common default name for a private key file.

2. Public Key:

o The public key is shared with others, allowing them to encrypt


messages that only you, with the corresponding private key, can
decrypt. It is safe to distribute your public key widely.

Example: id_rsa.pub is the corresponding public key file to the private


key id_rsa.
SSH Key Pair Usage:
1. Key Generation:

o Use a tool like ssh-keygen to generate an SSH key pair. This command
creates both the private and public keys.
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa

2. Key Storage:

o The private key is stored on your local machine in a secure location


(e.g., ~/.ssh/). The public key is shared with the servers you want to
access.

3. Key Exchange:

o When connecting to an SSH server, your client sends the public key to
the server during the authentication process.

Example: The public key might be added to the authorized_keys file on the
server.

4. Authentication:

o The server checks if the received public key matches any private key
stored on the server. If there is a match, the user is authenticated and
granted access.

Example: When connecting to a server, your private key is used to prove that
you possess the corresponding public key.

5. Passphrase:

o For additional security, you can add a passphrase to your private key.
This passphrase acts as a second layer of protection.

Example: When accessing your private key, you need to provide the
passphrase.
SSH Key Pair Usage Examples:
1. SSH Connection:

o Connect to a remote server using your private key:

ssh -i ~/.ssh/id_rsa user@remote-server

2. Copying Public Key:

o Use ssh-copy-id to add your public key to the authorized_keys file on a


remote server:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-server

3. GitHub or GitLab Authentication:

o Add your SSH public key to your GitHub or GitLab account to


authenticate when pushing or pulling code:

cat ~/.ssh/id_rsa.pub | pbcopy # Copy the public key to the


clipboard

Then, paste it into the SSH key settings on the respective platform.

By using SSH key pairs, you can securely authenticate and communicate with remote
servers or services without the need for passwords, enhancing both security and
convenience in various scenarios.

You might also like