簡體   English   中英

使用公共 SSH 密鑰失敗連接到本地主機

[英]Connect to localhost using public SSH key failure

我創建了一個 ansible 代碼來創建用戶並添加相應的 ssh 密鑰,該密鑰可以成功運行。 但是在嘗試訪問服務器時,它要求輸入密碼。

服務器是127.0.0.1 or localhost

Ansible 腳本

tasks:
    - include_vars: users.yml
    - name: Create user
      user:
        name: "{{item.username}}"
      with_items: "{{ users }}"

    - name: Adding SSH key
      authorized_key:
        user: "{{ item.username }}"
        key: "{{ lookup ('file', 'keys/'+ item.username + '.key.pub') }}"
      with_items: "{{ users }}"

我正在嘗試通過三種方式進行連接:

1. ssh user@localhost - Asking for password
2. ssh -vvv user@localhost - Asking for password
3. ssh-copy-id user@localhost - Asking for password

如果我在將詢問密碼標志設置為 no 時轉到 ssh 配置文件,然后運行 ​​anisble 腳本會給出權限問題,這是有效的情況,因為那時將不會配置用戶的公鑰。

我正在尋找的解決方案是一旦通過 ansible 腳本為用戶設置了 ssh 密鑰,他必須能夠使用 ssh 密鑰在沒有密碼的情況下登錄。

NOTE :-  The server is localhost/127.0.01 not any remote server ( I am learning so not using remote server) 

該問題已通過使用ssh-add基於此鏈接解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM