ssh-keygen -t rsa -C www1707 -f filename -P 123456
-t rsa 设置加密类型
-C www1707 设置标注
-f filename 定义生成的文件名称
-P 123456 用密码123456加密私钥
[[email protected] ~]# ssh-keygen -t rsa -C www1707 -f filename -P 123456 Generating public/private rsa key pair. Your identification has been saved in filename. Your public key has been saved in filename.pub. The key fingerprint is: 82:4b:49:83:c9:6a:25:83:c8:e3:fa:63:b0:2e:38:31 www1707 The key‘s randomart image is: +--[ RSA 2048]----+ | | |+. o | |o=+.o | |..=. + | |.o + . S | |E . . . | |o= . | |=.o | |o+.. | +-----------------+ [[email protected] ~]# ll total 12 -rw-------. 1 root root 1743 Jul 29 23:34 filename -rw-r--r--. 1 root root 389 Jul 29 23:34 filename.pub
查看私钥文件:
[[email protected] ~]# cat filename -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,E59C93328E0C7EF9 sluyNeFLBtMNcAW7gXlfaoLCQn8cVsSHCsMx05SFkoB136N0zL6Lnistwzr8+5Do 53uUF7WMLMaHd8pwqJimKUyQ0JhxGHaSySdMgeErqbIsI3HuyEYjfoyLmbv/qtSE X2HuKNCgj4QgFIkQhU85j4fJYR7PxCxaEtr1iwRLUWp84aEhoLcev/jF8fYnaNN+ QnmnXslDgLryGPuNKxD694lG1CK5XnDPzXPtfY6LgemHPCQThqXkDY4UGp0Zl0Ya GixE7m7n2L6XpbXz3kJHBSnOHVAv+GEgBykVHXEvBEQagOHSaQvG+ivFtvIoBAkl MLfhpSJuGUv1CA8wpnNT+rF7dIogLmMaoc/N2FaORsL4EeImaQhcxn6r9dWvuehV nJuCvQd6+XeSap4Vd/AgQ+BqlDwAPqWBuEkJZoisTCbybcqs4jb5ij8mkFU8Rrqc cZ1/Fwv+ycG8g8LSidfsus2L7KRVgpBSOCpMc2ietixnOEiFL0STeuldB4wcghbA nMVyWmzawIc6TP+53ym1TmKogAMTNT5uram4F5hy3wPmgaaUj1yjocjpsII39Yxj NzEeFZE1kyteoU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B3NzaC1yc2EAAAABIwAAAQEAsaD9gvSVHypRTCjlCw5U1l4M5Qs3N+fojWa6kEleWw+WGEp0NxdW3VdjO9zEhumC7c6yTtuMIBQe6tHnNR/aUFASFIKUAn4qZx8hkyySFg7cGAlJyoPKbOpc0iQqFHeJB36LLLSS/6mhSzu2M5Zz02kC5V7YY2kCaI2qmfByObDXfQk+TdflyIHoMREHUHyhGlZk+JbGkgCme5Dluwwg3Zy/CysHhQubyizsULwIjUv2p/Q+StxX37ZyMaH6+FpEBmDzCcPqzCeNdiKyX5UzzDFcfp1MFlVRdmOGj7cIptPsh+YeLjbOt29CYichl0RZ62Z1UsC4ls5KT/Gaedrl0w== www1707
将生成的公钥文件追加到/root/.ssh/authorized_keys文件中,添加信任关系
[[email protected] ~]# cat /root/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsaD9gvSVHypRTCjlCw5U1l4M5Qs3N+fojWa6kEleWw+WGEp0NxdW3VdjO9zEhumC7c6yTtuMIBQe6tHnNR/aUFASFIKUAn4qZx8hkyySFg7cGAlJyoPKbOpc0iQqFHeJB36LLLSS/6mhSzu2M5Zz02kC5V7YY2kCaI2qmfByObDXfQk+TdflyIHoMREHUHyhGlZk+JbGkgCme5Dluwwg3Zy/CysHhQubyizsULwIjUv2p/Q+StxX37ZyMaH6+FpEBmDzCcPqzCeNdiKyX5UzzDFcfp1MFlVRdmOGj7cIptPsh+YeLjbOt29CYichl0RZ62Z1UsC4ls5KT/Gaedrl0w== www1707
最后将私钥文件 filename 拷贝到需要连接该linux的机器上使用即可,使用时需要输入私钥的加密密码 123456
时间: 2024-10-13 11:17:26