Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux SSH 免密登錄配置:金鑰生成與分發兩步走

編輯:Linux 教學

環境:客戶端 192.168.0.5 → 服務端 192.168.0.10(root 用戶)。

操作流程

  1. 客戶端生成密鑰對:
    ssh-keygen -t rsa
    # 一路回車,生成 ~/.ssh/id_rsa (私鑰) 和 id_rsa.pub (公鑰)
  2. 推送公鑰至服務端:
    ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.10
    # 輸入一次密碼,公鑰自動追加至服務端 ~/.ssh/authorized_keys
  3. 驗證:
    ssh root@192.168.0.10
    # 應直接進入無需密碼

常見排查

  • 服務端 /etc/ssh/sshd_config 確保 PubkeyAuthentication yes、AuthorizedKeysFile .ssh/authorized_keys
  • 目錄權限:chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
  • SELinux 環境下執行 restorecon -Rv ~/.ssh
  • 非 root 用戶同理,路徑換為對應家目錄。
Copyright © Windows教程網 All Rights Reserved