Generating an SSH Key Pair
SSH keys allow you to establish a secure connection between two machines without using passwords. They are more secure and convenient than basic password authentication. Follow these steps to generate a public/private SSH key pair.
- Open the Terminal (Linux/Mac) or Git Bash (Windows).
- Type the following to generate a 4096-bit RSA key pair:
ssh-keygen -t rsa -b 4096
- You will be prompted to enter a file location and passphrase to protect the private key.
- Press Enter to accept the default location and leave the passphrase empty.
- The keys will be generated at ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key).
- To check the keys, type:
ls ~/.ssh
You should see the two new files.
- Print the public key contents with:
cat ~/.ssh/id_rsa.pub
This key can now be shared and installed on servers you want to access. The private key remains on your local machine.
- You can also generate keys with different names by specifying a -f option, e.g:
ssh-keygen -t rsa -b 4096 -f my_new_key
This will create my_new_key and my_new_key.pub.
That’s it! You’ve now generated an SSH key pair for stronger authentication. The private key should remain private, while the public key can be freely shared.