scp免密码登陆进行远程文件同步

一、建立公钥和私钥对

命令:ssh-keygen -t rsa

按Enter键,连续三次,默认存储路径及文件

在/home/.ssh/目录下,多了两个文件id_rsaid_rsa.pub,分别是私钥和公钥,这里我们只需要公钥即可。

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/.ssh/id_rsa.
Your public key has been saved in /home/.ssh/id_rsa.pub.
The key fingerprint is:
7a:ca:9f:9a:74:61:9c:d4:47:c3:ff:a8:a0:1c:26:06 root@rna
The key's randomart image is:
+--[ RSA 2048]----+
|           .o    |
|         . ...   |
|        . . ..   |
|    E  o . .  .  |
|     .  S      o |
|      ooo..   . .|
|     .o+oo . .   |
|     o =o.  .    |
|      =oo        |
+-----------------+

二、把公钥传到另一个主机

root@kali:~# scp id_rsa.pub root@192.168.16.117:~/.ssh/id_rsa.pub_temp  这里记得重命名一下,以免覆盖B主机原有的公钥

三、将id_rsa公钥的内容添加到.ssh目录下的authorized_keys文件,记得以追加的方式添加,以免将别的公钥覆盖,若文件不存在则新建。

四、完成

  

posted on 2018-03-11 18:19  萧飞IDO  阅读(335)  评论(0编辑  收藏  举报

导航