生成公鑰和私鑰文件
[root@localhost ~]# ssh-keygen -t rsa # -t選項(xiàng)指定需要加密的類型為rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y^H
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:
d5:5d:58:30:a7:45:a3:53:a8:ec:5d:89:19:7d:db:bb root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| =B*|
| . ++Bo|
| o oo* =|
| . o o.+.|
| S . . . .|
| . . . |
| .|
| E |
| |
+-----------------+
生成密鑰對(duì)文件
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# ll
total 12
-rw------- 1 root root 1675 Nov 16 23:39 id_rsa
-rw-r--r-- 1 root root 408 Nov 16 23:39 id_rsa.pub
-rw-r--r-- 1 root root 396 Nov 16 23:31 known_hosts
將公鑰文件id_rsa.pub,copy到需要無(wú)密碼登陸的服務(wù)器上
[root@localhost ~]# ssh-copy-id -i id_rsa.pub remoteIP
copy完成后會(huì)在遠(yuǎn)程服務(wù)器的.ssh/目錄下生成authorized_key文件
到此為止廊佩,已經(jīng)實(shí)現(xiàn)了兩臺(tái)服務(wù)器之間互相信任尉咕,可以適用于rsync的自動(dòng)備份環(huán)境中。