0
votes

Currently I am using vagrant box and ansible . My local config network is config.vm.network "private_network", ip: "192.168.33.10".

I added a user in vagrant box by using playbook-ansible:

  hosts: all
  remote_user: vagrant
  sudo: true
  tasks:
    authorized_key: user=root
                    key="{{ lookup('file','/home/root/.ssh/id_rsa.pub') }}"
                    path=/etc/ssh/authorized_keys/root
                    manage_dir=no

When I did vagrant ssh I could see the 'root' user in home directory and authorized key in /etc/ssh/authorized/toot, but when I do [email protected]

Agent admitted failure to sign using the key.

[email protected]'s password:

It is asking for password. I tries everything to login without password(ssh key based authentication).

2

2 Answers

0
votes

As you describe, the playbook did the job.
Check the ssh settings. Without knowing which box you use, that is hard to tell. For example: on ubuntu the default setting in the sshd_config file for PasswordAuthentication is yes.

0
votes

If I am not wrong, you are adding the key for root user but you mentioning it in the wrong dest directory:

hosts: all
  remote_user: vagrant
  sudo: true
  tasks:
    - name: Add Authorized Key for ROOT
      authorized_key: user={{ username }} 
                      key="{{ lookup('file','~/.ssh/id_rsa.pub') }}" 
                      state=present

Change key="{{ lookup('file','~/.ssh/id_rsa.pub') }}" to also like this, if it cannot find the key with relative path:

key="{{ lookup('file','/home/username/.ssh/id_rsa.pub') }}"

Uncomment this from /etc/ssh/sshd_config:

AuthorizedKeysFile      %h/.ssh/authorized_keys

if still, facing a problem, change this line also like this:

PasswordAuthentication no

Hope this will help you.