103ip 192.168.1.103
104ip 192.168.1.104
在103创建密钥,将公钥存放至104实现密钥访问104
1
2
3
4
| [root@103 ~]# useradd kai
[root@103 ~]# passwd kai
[root@104 ~]# useradd kai
[root@104 ~]# passwd kai
|
创建密钥
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| [kai@103 root]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/kai/.ssh/id_dsa): 存储位置
Created directory '/home/kai/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kai/.ssh/id_dsa. 私钥
Your public key has been saved in /home/kai/.ssh/id_dsa.pub. 公钥
The key fingerprint is:
SHA256:/V4sNcir8bA3Rqd3L+QFRjiNlA3X46Y96LspJm6oxUI kai@103
The key's randomart image is:
+---[DSA 1024]----+
| .oB.. |
| =.+..|
| o. .|
| . . .oo |
| E S . o.B. |
| . . ..*o+.|
| . o. o.==o..|
| o. o X=+= .|
| .. o.=o+*ooo|
+----[SHA256]-----+
[kai@103 root]$ ll /home/kai/.ssh/
总用量 8
-rw------- 1 kai kai 668 4月 18 15:31 id_dsa
-rw-r--r-- 1 kai kai 597 4月 18 15:31 id_dsa.pub
|
分发密钥
1
2
3
4
5
6
7
8
| [kai@103 root]$ ssh-copy-id -i /home/kai/.ssh/id_dsa.pub kai@192.168.1.104
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/kai/.ssh/id_dsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
kai@192.168.1.104's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'kai@192.168.1.104'"
and check to make sure that only the key(s) you wanted were added.
|