SSH, or Secure Shell, is a cryptographic network protocol used for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers. It is widely used by network administrators to manage systems and applications remotely, ensuring that data sent over the network is encrypted and secure from eavesdropping.
SSH cheatsheet
Here you can find how to configure a secure remote connection and command execution
# Getting started
What is an ssh?
# SSH with RSA key
What is an RSA key?
RSA (Rivest-Shamir-Adleman) is a public-key crypto system used for secure data transmission. An RSA key pair includes a public key for encryption and a private key for decryption. It is widely used in security protocols like SSL/TLS and SSH.
Types of RSA Keys
- Public Key: Can be shared with anyone and is used for encrypting data or verifying digital signatures/li>
- Private Key: Must remain secret and is used for decrypting data or signing digital documents.
RSA remains secure as long as the key length is sufficient (2048 or 4096 bits is the standard today). However, with the advancement of quantum computing, RSA encryption may become vulnerable in the future.
How Does RSA Work?
- Key Generation: Two large prime numbers are chosen, and their product is used as part of the public key.
- Encryption: A message is converted into a number and encrypted using the public key.
- Decryption: Only the holder of the private key can transform the encrypted message back into its original form.
- Digital Signatures: A document can be signed with the private key, and anyone can verify the signature using the public key.
Where is RSA Used?
- Secure connections (HTTPS, VPN, SSH)
- Authentication (e.g., SSH keys like id_rsa.pem)
- Digital signatures (documents, emails)
Create a Private PEM key
Open terminal and create a private PEM
ssh-keygen -t rsa -b 4096 -m PEM -f key_name.pem
- -t: Specifies the type of key to create (RSA).
- -b: Specifies the number of bits in the key (4096).
- -m: Specifies the key format (PEM).
- -f: Specifies the filename of the key file (key_name.pem).
Set permissions for the private key (required for SSH)
This is a commonly used permission set for SSH private keys (.pem), to ensure that they are secure and not accessible to other users on the system. Some SSH clients, such as OpenSSH, will refuse to use a private key if it has too permissive permissions.
chmod 400 key_name.pem
- chmod: Changes file permissions.
- 400: Sets read-only permissions for the owner.
Create a Public PEM key
Open terminal and create a public PEM
ssh-keygen -y -f key_name.pem > key_name.pub