您的位置:首页 > 博客中心 > 网络系统 >

linux ssh秘钥配置登录

时间:2022-04-03 13:14

#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
2a:ad:45:20:74:8b:bf:8f:c4:a8:6e:af:46:50:6b:ea root@localhost.localdomain
The key‘s randomart image is:
+--[ RSA 2048]----+
|  . .            |
| ..o .           |
| .o.o            |
|. oo .           |
|.o  . . S        |
|.. o + .         |
|o . = +          |
| E . *           |
|=oo.o .          |
+-----------------+
#ssh-copy-id -i ~/.ssh/id_rsa.pub 12.0.0.16
root@12.0.0.16‘s password: 
Now try logging into the machine, with "ssh ‘12.0.0.16‘", and check in:

  .ssh/authorized_keys

to make sure we haven‘t added extra keys that you weren‘t expecting.

[CCDT-QH-业务导航-1-root-<ccdt>]~#ssh 12.0.0.16
Last login: Sat Aug  5 10:27:32 2017 from 12.0.0.15
[CCDT-QH-业务导航-2-root-<~>]~#
#ssh-keygen -t rsa   三个回车生成密钥对
###生成rsa密钥对,默认保存在~/.ssh/{id_rsa,id_rsa.pub}
###id_rsa私钥自己保存的  id_rsa.pub公钥被连主机保存的

#ssh-copy-id -i ~/.ssh/id_rsa.pub 12.0.0.16
###将公钥copy到将要登录主机(12.0.0.16)中,默认(此位置是ssh配置文件中定义的)位置为~/.ssh/authorized_keys文件中

无需密码登录执行scp ssh 完成。。

服务器配置完整的步骤应该是:

(1)生成密钥公钥copy到服务器上,私钥保存在本地

(2)配置hosts.allow hosts.deny指名ssh允许链接的白名单

(3)禁止使用密码登录

(4)(可选)禁止root用户远程登录


go go go。。。

本文出自 “” 博客,请务必保留此出处

本类排行

今日推荐

热门手游