To generate a public key, you can use the ssh-keygen command. Here are the steps:
Open your terminal.
Run the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"-t rsaspecifies the type of key to create (RSA).-b 4096specifies the number of bits in the key (4096 is recommended for better security).-C "your_email@example.com"adds a comment (usually your email) to the key.
Follow the prompts:
- You will be asked where to save the key. Press Enter to accept the default location (
~/.ssh/id_rsa). - You can also set a passphrase for added security, or press Enter to leave it empty.
- You will be asked where to save the key. Press Enter to accept the default location (
Locate your public key: After the process is complete, your public key will be saved in the file
~/.ssh/id_rsa.pub. You can view it with:cat ~/.ssh/id_rsa.pub
You can now copy this public key to the target system's authorized_keys file to enable SSH access.
