机器A和机器B之间做一个公钥的信任,这样就可以在下次做scp的时候不需要进行密码验证 可以更好的实现自动化
讲一下原理:
假如服务器A上的一个pub(公钥)放到了互联网的任意一台机器B上了,那么服务器A此时若往服务器B上传数据或服务器A主动的想在服务器B上往自身cp数据都是需要进行验证的。
操作步骤:使用用户为root
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
27
28
29
30
31
32
33
34
|
[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
|
本文转自 xinsir999 51CTO博客,原文链接:http://blog.51cto.com/xinsir/1783549,如需转载请自行联系原作者