您的位置:首页 > 业界新闻

两台机器做互相信任 scp不使用密码

2016-05-26 17:21 253 查看
机器A和机器B之间做一个公钥的信任,这样就可以在下次做scp的时候不需要进行密码验证 可以更好的实现自动化

讲一下原理:
假如服务器A上的一个pub(公钥)放到了互联网的任意一台机器B上了,那么服务器A此时若往服务器B上传数据或服务器A主动的想在服务器B上往自身cp数据都是需要进行验证的。

操作步骤:使用用户为root
[root@TFSns ~]#  ssh-keygen -b 1024 -t 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
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:
aa:8a:3b:5b:d3:9e:6d:27:6e:1b:f5:21:46:78:b5:ec root@TFSns
The key's randomart image is:
+--[ RSA 1024]----+
|          .      |
|       . o .     |
|      . o o      |
|       o .       |
|        S E      |
|   .   + o .     |
|  o . o   .      |
|.o o ++..        |
|++..++++         |
+-----------------+
scp -p .ssh/id_rsa.pub  root@192.168.1.155:/root/.ssh/authorized_keys
root@192.168.1.155's password:
id_rsa.pub                                                                                                                                    100%  220     0.2KB/s   00:00

#在本机往155上主动传输数据:
[root@TFSns ~]# scp test.txt 192.168.1.155:/root/
test.txt                                                                                                                                                                                                                                                                          100%    0     0.0KB/s   00:00
#在本机主动的cp一个155的数据到本地
[root@TFSns ~]# scp 192.168.1.155:/root/test.txt ./
test.txt                                                                                                                                                                                                                                                                          100%    0     0.0KB/s   00:00
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息