linux下 scp命令不需要輸入使用者密碼

來源:互聯網
上載者:User

標籤:blog   io   for   檔案   sp   div   on   log   linux   

在兩台機器的兩個使用者之間建立安全的信任關係後,可實現執行scp命令時不需要輸入使用者密碼。

1. 在機器Client上root使用者執行ssh-keygen命令,產生建立安全信任關係的認證。

[[email protected] root]# ssh-keygen -b 1024 -t rsaGenerating 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: ……

  

注意:在程式提示輸入passphrase時直接輸入斷行符號,表示無認證密碼。

上述命令將產生私密金鑰認證id_rsa和密鑰憑證id_rsa.pub,存放在使用者目錄的.ssh子目錄中。

2. 將密鑰憑證id_rsa.pub複製到機器Server的root目錄的.ssh子目錄中,同時將檔案名稱更換為authorized_keys。

[[email protected] root]# scp -p .ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys[email protected]’s password: <– 輸入機器Server的root使用者密碼

在執行上述命令時,兩台機器的root使用者之間還未建立安全信任關係,所以還需要輸入機器Server的root使用者密碼。

經過以上2步,就在機器Client的root和機器Server的root之間建立安全信任關係。下面我們看看效果:

[[email protected] root]# scp -p text [email protected]:/root

  

成功了!真的不再需要輸入密碼了。

注意:不要吧使用者目錄的.ssh子目錄中私密金鑰認證id_rsa和密鑰憑證id_rsa.pub刪掉,否則就不好使了

linux下 scp命令不需要輸入使用者密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.