使用scp進行遠端資料傳輸時避免輸入密碼(scp without password)

來源:互聯網
上載者:User

假設本機為client,遠程機器為server。
舉例:從已登入的Client(192.168.1.1)複製目錄/usr/a到Server(192.168.1.2)的/usr目錄下,
命令如下:
scp -r /usr/a root@192.168.1.2:/usr
斷行符號之後等待片刻,提示輸入Server的密碼,
輸入正確密碼之後,
開始複製目錄a下的所有檔案到Server中。
如果只是複製一個檔案,
則去掉-r參數,如:
scp /usr/a/index.html root@192.168.1.2:/use/a/
你會發現使用命令操作,是一種非常方便、快捷的方式。但是,如果想不輸入密碼,則需要在兩台機器之間建立信任關係。

在機器Client的root和機器Server的root之間建立安全信任關係的步驟:
1. 在機器Client上root使用者執行ssh-keygen命令,產生建立安全信任關係的認證
        [root@Client 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:1c root@Client
        [root@Client root]#
注意:在程式提示輸入passphrase時直接輸入斷行符號,表示無認證密碼。
上述命令將產生私密金鑰認證id_rsa和密鑰憑證id_rsa.pub,存放在/root/.ssh/子目錄中。
2. 將密鑰憑證id_rsa.pub複製到機器Server的/root/.ssh/子目錄下,如果Server的/root/.ssh/下沒有authorized_keys,則直接將id_rsa.pub重新命名為authorized_keys,如果Server的/root/.ssh/下已經有authorized_keys檔案,則將id_rsa.pub的內容添加到authorized_keys檔案的尾部。[可以使用cat  id_dsa.pub >> authorized_keys命令,也可以使用vim開啟authorized_keys進行編譯。]
3. 現在可以使用scp進行遠端資料傳輸,同時又避免輸入密碼了。

from:http://blog.csdn.net/dupei/article/details/6177538

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.