Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of the basic usage of ssh-keygen command in SSH

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Ssh public key authentication is one of the ways of ssh authentication. Password-free login of ssh can be realized through public key authentication, and the ssh mode of git is also authenticated by public key.

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

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

When using ssh-keygen, 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 file location

Using ssh-kengen will generate two files under 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 you generate ssh key, you can specify the filename of the generated file with the-f option, as follows:

[huqiu@101 .ssh] $ssh-keygen-f test-C "test key" ~ ~ File name ~ ~ remarks

If you do not specify a file name, you will be asked for a file name:

[huqiu@101 .ssh] $ssh-keygenGenerating 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, and here we enter test.

After that, you will be asked if you need to enter a password. After entering the password, enter the password every time in the future. Please decide whether you need a password according to your security needs. If not, enter directly:

[huqiu@101 .ssh] $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:

[huqiu@101 .ssh] $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:

[huqiu@101 .ssh] $cat test.pubssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEAlgjiMw7AskxbvpQY9rmZPQxQBzh9laxFvbaini2EgmQkNsXBA9WJOXn2YBJauoiVsdUKBWA97avjsobrTxsCYvFr1yQQvTfTlbqlqGNIhQc/3HjTl2pIkClpDWvBrRN+jpyESS4MNbfOL1qjT4c/QhGvj6U6HrN6kUyn58oyyJpTzOLG74AZELJ2Led57QvTw1yJXZuAMWioR0A3BGd25fdocLX3ebux6ya8AsloOVYfsAqGlggrARe6FXjLfMH4a/nxaAdiDYVXU/Vr1ybK9P7SfyEDGJi3JtgiPUlA6vPxUCE+9IJPQaqqeqCGzrJ6G/XO7om1v9YLLG/H/ZN2tQ== test key ~ remarks

In order for private key files and public key files to work in authentication, make sure that permissions are correct.

For .ssh and the 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 execute permission, and other users can only have execute permission at most.

Since the above is the basic usage of the ssh-keygen command of SSH, I hope it will be useful to you. For more articles on the use of ssh-keygen, please see the following related articles.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report