歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux-scp不輸入密碼

Linux-scp不輸入密碼

日期:2017/2/28 15:46:06   编辑:Linux教程

以下是在機器A的root和機器B的root之間建立安全信任關系的步驟:

1. 在機器A上root用戶執行ssh-keygen命令,生成建立安全信任關系的證書。
[root@A root]# ssh-keygen -b 1024 -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:
49:9c:8a:8f:bc:19:5e:8c:c0:10:d3:15:60:a3:32:1croot@Client
[root@Client root]#
注意:在程序提示輸入passphrase時直接輸入回車,表示無證書密碼 。
上述命令將生成私鑰證書id_rsa和公鑰證書id_rsa.pub,存放在用戶家目錄的.ssh子目錄中。


2. 將公鑰證書id_rsa.pub復制到機器B的root家目錄的.ssh子目錄中,同時將文件名更換為authorized_keys。
[root@A]# scp -p .ssh/id_rsa.pub root@機器B的IP:/root/.ssh/authorized_keys
[email protected]'s password: <-- 輸入機器B的root用戶密碼
id_rsa.pub 100% |**************************| 218 00:00
[root@Client root]#
在執行上述命令時,兩台機器的root用戶之間還未建立安全信任關系,所以還需要輸入機器B的root用戶密碼。
經過以上2步,就在機器A的root和機器B的root之間建立安全信任關系。下面我們看看效果:
[root@A root]# scp -p textroot@機器B的IP:/root
text 100% |**************************| 19 00:00

########################################################################################

#ssh-keygen

後面會提示你私鑰的文件名,放在哪,這些問題,選擇默認就行了,中途會讓你輸入密碼,這個你可得記住。這樣你的用戶目錄下會多出一個隱藏的.ssh文件夾。可以使用ls -A 來查看。裡面還有兩文件,一個是id_rsa(私鑰),還有一個是id_rsa.pub(公鑰)

注:
(1)如果把A的公鑰給了B,那麼,可以在A上SCP不輸入密碼,進行傳輸B中的數據;
但 B上SCP時,仍需要密碼,如果需要雙方不輸入 密碼,則也要把B的公鑰給A;

(2)如果想讓B,C同時可以SCP不輸入密碼,傳輸A中的數據;
則要把B、C的公鑰都給 A;
操作步驟:把兩機器的id_rsa.pub中的數據都拷貝到A的/root/.ssh/authorized_keys文件中,一行表示一條;
或使用scp -p .ssh/id_rsa.pub root@機器B的IP:/root/.ssh/authorized_keys 先遠程拷貝過去一個,然後,另一個再手動拷貝進去;

Copyright © Linux教程網 All Rights Reserved