linux下實現免密傳輸文件或登陸到其餘服務器

使用scp傳輸文件到其餘服務器的時候,提示須要輸密碼,以下:服務器

[root@18c setup]# scp LINUX.X64_180000_db_home.zip 192.168.133.120:/u01dom

root@192.168.133.120's password:ssh

每次都要輸,很麻煩,咱們能夠創建兩臺服務器之間的互信關係,實現免密傳輸或登陸ide

步驟以下:server

(1)A主機生成配對祕鑰ip

[root@18c setup]# ssh-keygen -t rsaio

Generating public/private rsa key pair.ast

Enter file in which to save the key (/root/.ssh/id_rsa):登錄

Enter passphrase (empty for no passphrase):file

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 ~]#

相關文章
相關標籤/搜索