歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

ssh 密鑰認證及ssh scp無需輸入密碼的實現

經常在Linux間用scp命令傳輸文件,每次度需要輸入對方機器的密碼,非常麻煩。這種方式可以實現讓雙方自動通過密鑰認證,無需手動輸入密碼:

1,Root登陸,在兩邊機器執行以下命令並一路回車,生成RSA私鑰和公鑰:

[root@ ~]# cd .ssh

[root@ .ssh]# 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:

e7:ad:46:67:45:1a:df:da:cd:c7:32:e3:bf:76:8e:a9

2, 在兩邊機器查看/root/.ssh, 發現都生成兩個文件:id_rsa ,id_rsa.pub, id_rsa為私鑰,id_rsa.pub為公鑰:

[root@ .ssh]# ll

total 32

-rw------- 1 root root 1675 Aug 10 22:09 id_rsa

-rw-r--r-- 1 root root  415 Aug 10 22:09 id_rsa.pub

-rw-r--r-- 1 root root  222 Aug  8 22:52 known_hosts

3,在兩邊機器的/root/.ssh/目錄下分別建立authorized_keys文件,並將對方的公鑰id_rsa.pub文件內容考到authorized_keys上,這樣既可實現無需密碼傳輸文件了。

4,如果多個機器,將其他機器的公鑰文件內容追加到本機的authorized_keys文件中,既可實現本地向對方機器傳輸無需輸入密碼了。

本文出自 “小何貝貝的技術空間” 博客,請務必保留此出處http://babyhe.blog.51cto.com/1104064/636752

 

Copyright © Linux教程網 All Rights Reserved