centos設定ssh免密碼登陸

來源:互聯網
上載者:User

標籤:

準備工作:
    1、確認本機sshd的設定檔(需要root許可權)
  $ gedit /etc/ssh/sshd_config
  找到以下內容,並去掉注釋符”#“
  RSAAuthentication yes
  PubkeyAuthentication yes
  AuthorizedKeysFile      .ssh/authorized_keys
   2、如果修改了設定檔需要重啟sshd服務 (需要root許可權)
  $ /sbin/service sshd restart


配置SSH無密碼登入需要3步:
    1.產生公開金鑰和私密金鑰
    2.匯入公開金鑰到認證檔案,更改許可權
    3.測試


1.產生公開金鑰和私密金鑰
  Shell代碼:  ssh-keygen -t rsa
  
   預設在 ~/.ssh目錄產生兩個檔案:
    id_rsa      :私密金鑰
    id_rsa.pub  :公開金鑰


2.匯入公開金鑰到認證檔案,更改許可權
    2.1 匯入本機
        Shell代碼:  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys  


    2.2 匯入要免密碼登入的伺服器
        首先將公開金鑰複製到伺服器
        Shell代碼:  scp ~/.ssh/id_rsa.pub [email protected]:/home/id_rsa.pub  


        然後,將公開金鑰匯入到認證檔案(這一步的操作在伺服器上進行)
        Shell代碼:  cat /home/id_rsa.pub >> ~/.ssh/authorized_keys 
 
    2.3 在伺服器上更改許可權
       Shell代碼:   chmod 700 ~/.ssh
                    chmod 600 ~/.ssh/authorized_keys  

centos設定ssh免密碼登陸

聯繫我們

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