使用scp传输文件到其他服务器的时候,提示需要输密码,如下:
[root@18c setup]# scp linux.X64_180000_db_home.zip 192.168.133.120:/u01
root@192.168.133.120's password:
每次都要输,很麻烦,我们可以建立两台服务器之间的互信关系,实现免密传输或登录
步骤如下:
(1)A主机生成配对秘钥
[root@18c setup]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
fb:00:4f:76:c5:73:da:ef:3a:e6:a4:b2:66:f9:94:26 root@18c
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
| + . |
| . = |
| . S . . . |
| = o . . |
| + E.+ . .|
| o=+ oo. |
| oo+oooo.|
+-----------------+
[root@18c setup]#
(2)将/root/.ssh目录下生成的id_rsa.pub文件传输到B机的/root/.ssh下,如果B机不存在.ssh目录,需要手工创建,并且命名为authorized_keys
[root@18c .ssh]# scp id_rsa.pub 192.168.133.120:/root/.ssh/authorized_keys
root@192.168.133.120's password:
id_rsa.pub 100% 390 0.4KB/s 00:00
[root@18c .ssh]#
(3)验证从A机传输文件到B机,可以看到能免密传输
[root@18c setup]# scp LINUX.X64_180000_db_home.zip 192.168.133.120:/u01
LINUX.X64_180000_db_home.zip 22% 997MB 115.6MB/s 00:29 ETA^CKilled by signal 2.
免密登录
[root@18c setup]# ssh 192.168.133.120
Last login: Sat Sep 8 00:59:14 2018 from 192.168.133.111
[root@dbserver ~]#