Detailed explanation of the basic usage of SSH's ssh-keygen command

Detailed explanation of the basic usage of SSH's ssh-keygen command

SSH public key authentication is one of the SSH authentication methods. SSH password-free login can be achieved through public key authentication, and git's SSH method is also authenticated by public key.

In the home directory of the user directory, there is a .ssh directory. Almost all the files related to the current user's ssh configuration authentication are in this directory.

ssh-keygen can be used to generate the public and private key files required for ssh public key authentication.

When using ssh-keygen, please go to the ~/.ssh directory first. If it does not exist, please create it first. And make sure that the permissions of ~/.ssh and all parent directories cannot be greater than 711

Generated file name and location

Using ssh-kengen will generate two files in the ~/.ssh/ directory. When the file name and key type are not specified, the two files generated by default are:

id_rsa

id_rsa.pub

The first is the private key file and the second is the public key file.

When generating an ssh key, you can specify the file name of the generated file through the -f option, as follows:

[[email protected]]$ ssh-keygen -f test -C "test key"
               ~~File Name~~~~ Notes

If no file name is specified, you will be asked to enter one:

[[email protected]]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/huqiu/.ssh/id_rsa):

You can enter the file name you want, here we enter test.

After that, you will be asked if you need to enter a password. After entering the password, you will need to enter it every time thereafter. Please decide whether you need a password based on your security needs. If not, just press Enter:

[[email protected]]$ ssh-keygen -t rsa -f test -C "test key"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

If the file name is test, the result is:

[[email protected]]$ll test*
-rw------- 1 huqiu huqiu 1675 Sep 15 13:24 test
-rw-r--r-- 1 huqiu huqiu 390 Sep 15 13:24 test.pub

In the command generated above, the -C option is a comment in the public key file:

[[email protected]]$ cat test.pub
ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAQEAlgjiMw7AskxbvpQY9rmZPQxQBzh9laxFvbaini2EgmQkNsXBA9WJOXn2YBJauoiVsdUKBWA97avjsobrTxsCYvFr1yQQvTfTlbqlqGNIhQc/3HjTl2pIkClpDWvBrRN+jpyESS4MNbfOL1qjT4c/QhGvj6U6HrN6kUyn58oyyJpTzOLG74AZELJ2Led57QvTw1yJXZuAMWioR0A3BGd25fdocLX3ebux6ya8AsloOVYfsAqGlggrARe6FXjLfMH4a/nxaAdiDYVXU/Vr1ybK9P7SfyEDGJi3JtgiPUlA6vPxUC
E+9IJPQaqqeqCGzrJ6G/XO7om1v9YLLG/H/ZN2tQ== test key
                      ~~~~Remarks

In order for the private key file and public key file to work in authentication, please ensure that the permissions are correct.

For .ssh and its parent folder, the current user must have execute permission, and other users can only have execute permission at most.

The same is true for public and private key files: the current user must have execution permissions, and other users can only have execution permissions at most.

The above is the basic usage of SSH's ssh-keygen command. I hope it is useful to everyone. For more articles about the usage of ssh-keygen, please see the following related articles

You may also be interested in:
  • SSH remote login and port forwarding detailed explanation
  • Install OpenSSH on Windows and log in to the Linux server by generating an SSH key
  • Unbind SSH key pairs from one or more Linux instances
  • In-depth analysis of the three components of SSH: ssh, sftp, and scp
  • Use PSSH to batch manage Linux servers
  • Detailed explanation of Redis unauthorized access and SSH key file utilization
  • SSH principle and two login methods detailed illustration
  • How to create a Docker image that supports SSH service
  • How to add or modify SSH port number in CentOS7
  • How to set up SSH remote debugging in PyCharm
  • Detailed explanation of a simple example of webssh based on Django
  • How to upload files and folders to Linux server via SSH
  • How to modify the default port number of CentOS6.5 and CentOS7 ssh
  • Spring+Hibernate+Struts(SSH) framework integration practice
  • How to install ssh service and realize remote access in ubuntu16.04
  • How to specify ssh port for rsync file synchronization
  • Use Python to update the ssh remote code to operate the remote server implementation code
  • How to write a lightweight ssh batch operation tool in Go
  • SSH port forwarding, local port forwarding, remote port forwarding, dynamic port forwarding details

<<:  Detailed explanation of Vue's seven value transfer methods

>>:  A comprehensive summary of frequently used statements in MySQL (must read)

Recommend

Detailed explanation of the use of Teleport in Vue3

Table of contents Purpose of Teleport How Telepor...

mysql show simple operation example

This article describes the mysql show operation w...

Detailed explanation of the use of custom parameters in MySQL

MySQL variables include system variables and syst...

The actual process of implementing the guessing number game in WeChat applet

Table of contents Function Introduction Rendering...

MySQL column to row conversion and year-month grouping example

As shown below: SELECT count(DISTINCT(a.rect_id))...

Detailed explanation of custom configuration of docker official mysql image

In order to save installation time, I used the of...

Detailed explanation of table return and index coverage examples in MySQL

Table of contents Index Type Index structure Nonc...

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

mysql5.7 create user authorization delete user revoke authorization

1. Create a user: Order: CREATE USER 'usernam...