1. 程式人生 > >Jenkins進階系列之——09配置Linux系統ssh免密碼登陸

Jenkins進階系列之——09配置Linux系統ssh免密碼登陸

dom pub tar finger cnblogs pan 改變 art home

ssh認證的完整描述:https://www.ibm.com/developerworks/cn/linux/security/openssh/part1/

說明:點我去查看

今天我們只說生成ssh的key,從而達到免密碼登陸的目的。

不知道ssh是什麽的自己看說明。好了,不廢話了。

系統:CentOS 5.8

  1. 確認用戶

    確認當前用戶是你需要的用戶!

    $ whoami
    froad    #froad用戶,根據你自己的需求選擇用戶。我這兒用froad用戶演示。

  2. 生成key 技術分享
    $ cd ~ #回到用戶目錄,不回去也沒有關系
    $ ssh-keygen     
    #可以使用-t選項選擇加密方式,包括 RSA 和 DSA 兩種密鑰
    #例如:$ssh-keygen -t dsa 或者ssh-keygen -t rsa
    #加密方式不同,key的名稱不同,其他沒有區別
    #如果沒有指定密鑰,默認RSA
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/froad/.ssh/id_rsa): #私鑰存放的位置,默認會存放在用戶目錄的.ssh文件夾,直接回車
    Enter passphrase (empty for no passphrase): #默認,回車
    Enter same passphrase again: #默認,回車
    Your identification has been saved in /home/froad/.ssh/id_rsa.#私鑰路徑
    Your public key has been saved in /home/froad/.ssh/id_rsa.pub.#公鑰路徑
    The key fingerprint is:
    e8:b6:e6:xxxxxxxxxxxxxxxxx:ec:b5:d8 [email protected]
/* */ $ cat id_***.pub >> authorized_keys #***代表加密方式,將公鑰拷貝到authorized_keys文件中。如果你有很多的電腦需要配置,將所有的id_***.pub公鑰拷貝到一個authorized_keys文件中即可 技術分享
  • 配置

    將authorized_keys文件拷貝到需要被管理的電腦上。註意:放在用戶目錄下.ssh文件夾中。Linux用戶會限制你的訪問權限

  • 驗證

  • 技術分享
    $ ssh [email protected]
    #root是用戶名,可以根據你的需求改變
    The authenticity of host ‘192.168.2.xxx (192.168.2.xxx)‘ can‘t be established.
    RSA key fingerprint is ff:07:49:4d:xxxxxxxxxxe:2c:38.
    Are you sure you want to continue connecting (yes/no)? yes
    #同意將指紋添加到本地
    Warning: Permanently added ‘192.168.2.xxx‘ (RSA) to the list of known hosts.
    Last login: Wed Oct 23 13:58:32 2013 from 192.168.1.xxx
    技術分享

    只能在你生成key的電腦上訪問authorized_keys的電腦,如果你想兩臺電腦互相訪問均免密碼。那麽你還需要重復上面的步驟(機器的配置剛好相反)。

  • 其他
  •   如果添加指紋的時候提示添加失敗,是因為你以前添加過了這個ip的指紋。

       解決辦法:將.ssh目錄的known_hosts文件刪除掉(好粗暴啊( ⊙ o ⊙ )啊!),也可以打開這個文件把對於ip的那條記錄刪除(這個就精細多了O(∩_∩)O哈哈~)

      如果操作步驟都正確,但是依然要求輸入密碼。一般是因為權限的問題。命令如下

    chmod 644 ~/.ssh/authorized_keys

    Jenkins進階系列之——09配置Linux系統ssh免密碼登陸