How to generate a new SSH key pair in linux
Open a terminal.
Type the following command and press Enter:
ssh-keygen -t rsa -b 4096
This command generates a new RSA SSH key pair with a key length of 4096 bits.
You will be prompted to choose a location to save the key pair. Press Enter to accept the default location (
~/.ssh/id_rsa
).You will be prompted to enter a passphrase for the key pair. It is recommended to provide a passphrase for added security, but you can also leave it blank by pressing Enter.
Once the key pair is generated, you can display the public key by :
cat ~/.ssh/id_rsa.pub
The output will be your newly generated public SSH key.
Remember, the public key is safe to share with others or use for authentication, while the private key (typically id_rsa
) should be kept secure and not shared with anyone.
ย