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

10 reasons why Linux is becoming more and more popular

Linux has been loved by more and more users. Why ...

MySQL common backup commands and shell backup scripts sharing

To back up multiple databases, you can use the fo...

A brief analysis of MySQL locks and transactions

MySQL itself was developed based on the file syst...

A brief discussion on the performance issues of MySQL paging limit

MySQL paging queries are usually implemented thro...

How to automatically start RabbitMq software when centos starts

1. Create a new rabbitmq in the /etc/init.d direc...

Detailed explanation of MySQL slow log query

Slow log query function The main function of slow...

How to create and run a Django project in Ubuntu 16.04 under Python 3

Step 1: Create a Django project Open the terminal...

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

Introduction to the common API usage of Vue3

Table of contents Changes in the life cycle react...

Analysis of the reasons why MySQL's index system uses B+ tree

Table of contents 1. What is an index? 2. Why do ...

CentOS uses local yum source to build LAMP environment graphic tutorial

This article describes how to use the local yum s...

How to remove the dividing line of a web page table

<br />How to remove the dividing lines of a ...

Vue.js cloud storage realizes image upload function

Preface Tip: The following is the main content of...

WePY cloud development practice in Linux command query applet

Hello everyone, today I will share with you the W...