Master ssh-keygen in Linux
In Linux, the ssh-keygen command is used to generate and manage SSH key pairs. Its basic usage is as follows:
- Open the terminal.
- Please input the following command:
- Generate a new SSH key
- To generate key pairs for specific users, you can use the following command:
- Generate a SSH key at the specified path.
- In this case, /path/to/ssh/key is the path and file name for generating the key pair.
- Next, the command will prompt you to enter a storage location and file name for the key, which by default will be stored in the user’s .ssh directory with the file names id_rsa (private key) and id_rsa.pub (public key).
- Next, the command will prompt you to enter a password to protect the private key. You have the option to either set a password or leave it blank.
- After completing the steps above, ssh-keygen will generate a pair of keys.
- Your identification information has been stored in /path/to/ssh/key. Your public key has also been stored in /path/to/ssh/key.pub. The fingerprint of the key is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user@host. Additionally, the key’s randomart image is displayed above.
- Now, you can deploy the public key id_rsa.pub to the remote server for SSH key authentication.
Note: When using the ssh-keygen command, you can customize the type, length, encryption algorithm, and other options of the key. You can use the man ssh-keygen command to view a complete list of options and detailed explanations for ssh-keygen.