Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

通用-1_ssh_pubkey.yaml

  • 提前生成ed25519格式的密钥对

    ssh-keygen -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C email@email.cn
    
  • 脚本内容

    - hosts: prod
      tasks:
        - name: Create .ssh directory
          file:
            path: /home/ubuntu/.ssh
            state: directory
        - name: ssh-copy
          authorized_key:
            user: ubuntu
            key: "{{ lookup('file', '/home/ubuntu/.ssh/id_ed25519.pub') }}"
          tags:
            - sshkey