linux配置ssh公鑰認證,打通root用戶的免密碼輸入的scp通道

1.ssh-keygenhtml

     ssh-keygen是unix-like系統的一個用來生成、管理ssh公鑰和私鑰的工具。linux


2.用法算法

經常使用的重要的選項有:vim

-b num   指定生成多少比特長度的key,單位爲b,默認爲1024b服務器

-t    指定生成key的類型,也就是使用哪種加密算法,可選的有rsa1 | rsa | dsadom

 

3.ssh

[root@iDirector ~]# 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:
23:12:af:af:37:ea:e5:2d:49:63:97:27:d4:bf:2d:75 root@iDirector
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|    .    .       |
|     o  . .      |
|    . o.S. .     |
|     o+.+.. . . E|
|    .o.+ o   + . |
|     +=.    o .  |
|   .++oo.    .   |
+-----------------+
[root@iDirector ~]# ll /root/.ssh/
id_rsa       id_rsa.pub   known_hosts 
在程序提示輸入passphrase時直接輸入回車,表示無證書密碼。 上述命令將生成私鑰證書id_rsa和公鑰證書id_rsa.pub,存放在用戶家目錄的.ssh子目錄中。 


轉載自:http://www.361way.com/ssh-public-key/3662.html

在兩臺linux主機上因爲環境的須要,常常要配置兩臺主機之間免密碼登陸,這就要用到key認證,也就是所謂的公私鑰認證。
便於理解,我這裏指定兩臺主機爲 A 和 B 。若是A主機想免密碼登陸到B主機上,則A主機上存放私鑰,B 主機上存放公鑰。
經過ssh-keygen 命令生成的兩個文件爲:公鑰文件 ~/.ssh/id_rsa.pub; 私鑰文件 ~/.ssh/id_rsa 。
而B主機上存放公鑰時,須要將id_rsa.pub的內容存放到~/.ssh/authorized_keys 文件內,而且保證權限爲600

    #將key導入到遠程的B主機上,並修改權限
   #在A主機上操做
$ cat /root/.ssh/id_rsa.pub | ssh root@遠程服務器ip 'cat - >> ~/.ssh/authorized_keys' #B主機上操做 $ chmod 600 ~/.ssh/authorized_keys

不過還有更簡單的方法,不須要在B主機上再修改權限 ,而直接將公鑰內容導入到遠程主機上,使用ssh-copy-id命令,以下:ide

 

$ ssh-copy-id  -i /root/.ssh/id_rsa root@xxx,xxx,xxx,xxx

 

配置完key後,須要在sshd_config文件中開啓key認證工具

    $ vim /etc/ssh/sshd_config
    PubkeyAuthentication yes  //將該項改成yes    

修改完成後,經過/etc/init.d/sshd restart 重啓ssh服務從新加載配置。若是想要禁用密碼認證,更改以下項:加密

    $ vim /etc/ssh/sshd_config
    UsePAM yes
    爲
    UserPAM no

 

 

轉載自:http://blog.csdn.net/aabbcc456aa/article/details/18981279

如何讓鏈接新主機時,不進行公鑰確認?

在首次鏈接服務器時,會彈出公鑰確認的提示。這會致使某些自動化任務,因爲初次鏈接服務器而致使自動化任務中斷。或者因爲  ~/.ssh/known_hosts 文件內容清空,致使自動化任務中斷。 SSH 客戶端的 StrictHostKeyChecking 配置指令,能夠實現當第一次鏈接服務器時,自動接受新的公鑰。只須要修改 /etc/ssh/ssh_config 文件,包含下列語句:

 

Host *
 StrictHostKeyChecking no

 

或者在 ssh 命令行中用 -o 參數

 

$ ssh  -o StrictHostKeyChecking=no  192.168.0.110
相關文章
相關標籤/搜索