Permalink: 2016-07-08 10:50:00+08:00 by terry in Linux tags: ssh
  1. linux Server 运行下面命令:
ssh-keygen -t rsa -P ''

例如:

[root@vcentos .ssh]# ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
21:d8:b7:0c:1b:09:02:9b:50:b3:35:55:59:9a:31:bf root@vcentos.vlinux
The key's randomart image is:
+--[ RSA 2048]----+
|oo+ +...+o.      |
|.o = = ..*       |
|o . . * = .      |
|       B o .     |
|      . S E      |
|                 |
|                 |
|                 |
|                 |
+-----------------+
  1. 在Server 上查看 .ssh/目录
[root@vcentos .ssh]# ll
total 16
-rw-------. 1 root root  402 Jul  8 10:03 authorized_keys
-rw-------. 1 root root 1675 Jul  8 10:04 id_rsa
-rw-r--r--. 1 root root  401 Jul  8 10:04 id_rsa.pub
-rw-r--r--. 1 root root  396 Jul  1 14:56 known_hosts
  1. 将公钥id_rsa.pub,拷贝到client 上,并且把id_rsa.pub添加到客户机.ssh/authorzied_keys文件里
cat id_rsa.pub >> .ssh/authorized_keys

4.更改authorized_keys的权限为600

chmod 600 .ssh/authorized_keys
  1. 然后尝试从client上登陆server
[root@vcentos ~]# ssh 192.168.95.22
The authenticity of host '192.168.95.22 (192.168.95.22)' can't be established.
ECDSA key fingerprint is 49:e8:67:50:33:0f:cc:2c:26:a3:aa:6b:7d:ed:24:59.
Are you sure you want to continue connecting (yes/no)?

输入yes

只有第一次才需要进去确认。