用途

生成ssh加密算法需要使用到的秘钥以及管理和转换

用法

     ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i [-f input_keyfile]
ssh-keygen -e [-f input_keyfile]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
ssh-keygen -l [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-f known_hosts_file] [-l]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-f input_keyfile] [-g]
ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
ssh-keygen -T output_file -f input_file [-v] [-a num_trials] [-W generator]
ssh-keygen [-n] [-D smartcard]
ssh-keygen -s ca_key -I certificate_identity [-h] [-Z principals] [-O option] [-V validity_interval]
[-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]

常用选项

-B

显示秘钥文件的bubblebabble摘要

-b bits

秘钥长度,长度越长,加密越安全,默认是2048个比特

-C comment

设置注释

-c

请求修改备注,只支持RSA1算法的秘钥文件,如果文件设置了密码,会提示输入密码

-D pkcs11

下载存储在pkcs11的RSA公钥

-e

读取OpenSSH公钥文件内容,转换成RFC 4716 SSH Public Key File Format格式,然后输出到stdout

-F hostname

从known_hosts文件查找hostname,没有指定文件,默认查找~/.ssh/known_hosts。只能查找域名,ip查询不了。

-f filename

指定秘钥文件完整路径

-G output_file

(Generate candidate primes for DH-GEX. These primes must be screened for safety (using the -T option) before use.)

-g

(Use generic DNS format when printing fingerprint resource records using the -r command.)

-H

(Hash a known_hosts file. This replaces all hostnames and addresses with hashed representations within the specified file; the original content is moved to a file with a .old suffix. These hashes may be used normally by ssh and sshd, but they do not reveal identifying information should the file’s contents be disclosed. This option will not modify existing hashed hostnames and is therefore safe to use on files that mix hashed and non-hashed names.)

-h

(When signing a key, create a host certificate instead of a user certificate.)

-I

(Specify the key identity when signing a public key.)

-i

(This option will read an unencrypted private (or public) key file in SSH2-compatible format and print an OpenSSH compatible private (or public) key to stdout.)

-L

输出证书的内容

-l

显示公钥指纹

-M memory

(Specify the amount of memory to use (in megabytes) when generating candidate moduli for DH-GEX.)

-n

(Extract the public key from smartcard.)

-N new_passphrase

设置文件密码

-P passphrase

(Provides the (old) passphrase.)

-p

请求修改文件密码

-q

安静模式

-R hostname

(Removes all keys belonging to hostname from a known_hosts file.)

-r hostname

(Print the SSHFP fingerprint resource record named hostname for the specified public key file.)

-s ca_key

(Certify (sign) a public key using the specified CA key.)

-t type

设置创建的秘钥类型.

(The possible values are “rsa1” for protocol version 1 and “dsa”, “ecdsa” or “rsa” for protocol version 2.)

-v

调试模式

-y

(This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.)

实践

1 提取符合标准格式的公钥

[root@vm ssh]# ssh-keygen -e -f ssh_host_rsa_key
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "2048-bit RSA, converted from OpenSSH by root@vm"
AAAAB3NzaC1yc2EAAAABIwAAAQEAvF/iYFaWAMBMdAA4888pq1uxL34ptaEci/H0aG21eW
eloNtM/QPx8DiSTOcF7rT/i0BLMBAzNKdSZOZHBdG8Apf5VWsfNyKQ6a5qEfV26lr6CKg8
zPgdLoA8bQYarjN+LKrYWT9xteafVw9TLAtQAAdZFePkUkIKBMVhn48kM95HHOF6hcua99
TcJ0AyvcFof+ebLyGznXKxrf2sliAHwaCWwO7rHhuIRJvCyDmrzh4NffozRqVfJEm2c90H
3397Nd6seCOHOUVNRz2l69hfYWOPuuvlS2aQicbU9touw5f4ZvDTFxpyn2ZvqGaZzvBril
/QF/qbEsKYsCVCWaUYMQ==
---- END SSH2 PUBLIC KEY ----

2 查找github.com主机key信息

[root@vm ssh]# ssh-keygen -H -F github.com
# Host github.com found: line 5 type RSA
|1|+31fGJzfnYKj7Mzk9ncYS2pZ7sI=|C0orBfR1oH2VQ9ij2gRz9QBOAyk= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg733www+wC604ydGXA8VJiS5ap43JXiUFFAaQ==

3 显示公钥指纹

[root@vm ssh]# ssh-keygen -l -f ./ssh_host_rsa_key.pub
2048 90:05:de:31:8c:ff:ba:5a:2b:b3:80:b5:61:68:52:52 ./ssh_host_rsa_key.pub (RSA)

4 生成rsa公私钥

[root@vm ~]# ssh-keygen -v -b 2048  -t rsa -C "rsa key file ,just a test" -f ./test_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ./test_key.
Your public key has been saved in ./test_key.pub.
The key fingerprint is:
f0:66:15:6d:cd:cb:e7:d2:b9:ce:b5:dc:44:ff:97:f0 rsa key file ,just a test
The key's randomart image is:
+--[ RSA 2048]----+
| .. o |
| .o o |
| . .. . . |
| o . o .|
| S +o|
| o ..o+|
| o.*|
| oE*|
| .=+|
+-----------------+

参考资料

【1】man ssh-keygen

N天学习一个linux命令之ssh-keygen的更多相关文章

  1. N天学习一个linux命令之ssh

    用途 通过加密连接,远程登录主机和在远程主机执行命令,也可以用于转发x11和tcp,也可用于搭建VPN.第一次连接时,会弹出远程主机公钥指纹确认信息,通过这个方式防止中间人攻击. 用法 ssh [op ...

  2. N天学习一个Linux命令之帮助命令:man

    前言 工作中每天都在使用常用的命令和非常用的命令,忘记了用法或者参数,都会bing一下,然后如此循环.一直没有真正的系统的深入的去了解命令的用法,我决定打破它.以前看到有人,每天学习一个linux命令 ...

  3. N天学习一个linux命令之scp

    用途 通过ssh通道,不同主机之间复制文件 用法 scp [options] [user@host:]file1 [user2@host2:]file2 常用参数 -1使用 ssh 1协议 -2使用s ...

  4. N天学习一个Linux命令之free

    用途 查看系统内存(物理/虚拟/缓存/共享)使用情况 用法 free [-b | -k | -m | -g | -h] [-o] [-s delay ] [-c count ] [-a] [-t] [ ...

  5. N天学习一个linux命令之ping

    用途 检测主机是否可到达,也就是说,目标主机是否可以联网,还可以用于检测网速.通过发送ICMP ECHO_REQUEST数据包检测. 用法 ping [options] destination 常用选 ...

  6. N天学习一个linux命令之kill

    用途 用于终止进程 用法 kill [-s signal|-p] [--] pid... kill -l [signal] 说明 1.默认发送信号15(请求终止进程,程序可以捕获,操作系统会杀死没有对 ...

  7. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  8. 每天学习一个Linux命令-目录

    在工作中总会零零散散使用到各种Linux命令,从今天开始详细的学习一下linux常用命令,坚持每天一个命令,学习的主要参考资料为: 1.竹子-博客(https://www.cnblogs.com/pe ...

  9. N天学习一个linux命令之umask

    前言 umask不是linux命令,而是shell内置的指令,俗称用户权限掩码,用于对用户创建的文件和目录设置默认权限.默认的权限掩码是0022,也就是说新创建的文件权限是0644,新创建的目录权限是 ...

  10. N天学习一个linux命令之ip

    用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...

随机推荐

  1. FTP FtpWebRequest 异步上传文件

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  2. 对于Mobile模块化的概念认知(小白)

    最近刚刚学习了Mobile的一些基础知识,把它整理一下方便自己的学习 那什么是Mobile呢? 自己的理解是将一个项目中共同的部分抽出来,这样就形成了Mobile模块. 为什么要使用Mobile呢? ...

  3. 简单认识http协议

    1.什么是TCP/IP  如果要了解一个人,可以从他归属的集体聊起来.我们的HTTP协议就属于TCP/IP协议家族中的一员,了解HTTP协议再整个网络流程中的地位,也能更加充分的理解HTTP协议. 要 ...

  4. EF在应用程序配置文件中找不到名为“XXX”的连接字符串。

    现象: 在配置EF的时候需要如题所述的问题,仔细检查了在EF实体模型对应程序集下的APP.Config文件中的ConnectionString配置项有了XXX项的数据库字符串的配置: <conn ...

  5. Android通过透明度设置背景变暗

    变暗 WindowManager.LayoutParams lp=getWindow().getAttributes(); lp.alpha=0.3f; getWindow().addFlags(Wi ...

  6. mysql下载和安装Windows服务

    一.下载mysql:https://dev.mysql.com/downloads/mysql/,解压拷贝到D:\software\mysql-8.0.13-winx64 二.在D:\software ...

  7. Rsync 传输不需要输入密码

    1.背景 1)        一个作为服务器端:VM3(IP: 3.9.8.151) 2)        一个作为客户端:VM2(IP: 3.9.8.157) 3)        服务器端和客户端网络 ...

  8. html5——颜色

    CSS2 1.opacity,可以设置透明度,但是父盒子设置了透明度会影响子盒子 CC3 1.transparent属性,但是不可改变透明值 2.rgba():r--red g--green b--b ...

  9. PHP 之phpqrcode类库生成二维码

    <?php /** * Created by PhpStorm. * User: 25754 * Date: 2019/6/4 * Time: 15:53 */ include "./ ...

  10. resize监听div的size变化

    具体实现分两类, ie9-10 默认支持div的resize事件,可以直接通过div.attachEvent('onresize', handler);的方式实现 其它浏览器 通过在div中添加一个内 ...