# issue using remote\_user

**URL:** <https://forum.ansible.com/t/issue-using-remote-user/17000>\
**Category:** Ansible Project\
**Created:** [December 9, 2014, 6:14pm UTC](https://forum.ansible.com/t/issue-using-remote-user/17000 "2014-12-09T18:14:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aarif\_mohamed](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@aarif\_mohamed](https://forum.ansible.com/u/aarif_mohamed)\
**Post date:** [December 9, 2014, 6:14pm UTC](https://forum.ansible.com/t/issue-using-remote-user/17000/1 "2014-12-09T18:14:33Z")

</div>

```auto
Hi all, I ran the ansible-playbook using the file below and got the following errors. 

```

```auto
FILE: file.yml
---
- hosts: g1
  remote_user: root
  tasks:
    - name: test connection
      ping:
      remote_user: yourname

```

```auto
:::ERROR:::

```

```auto
PLAY [g1] *********************************************************************

GATHERING FACTS ***************************************************************
ok: [xxx.srv.xxx.de]

TASK: [test connection] *******************************************************
fatal: [xxx.srv.xxx.de] => {'msg': "FAILED: ('Bad authentication type', [u'publickey', u'gssapi-with-mic', u'keyboard-interactive']) (allowed_types=[u'publickey', u'gssapi-with-mic', u'keyboard-interactive'])", 'failed': True}

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/yourname/x.retry

xxx.srv.xxx.de : ok=1 changed=0 unreachable=1 failed=0

PS: IF i set same password for root and "yourname", It is working fine. 

```

```auto
Is it a bug or am i missing some basic setting in the script? Could anyone please help me with this issue?

```

```auto
Thanks in advance

```

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [December 9, 2014, 11:49pm UTC](https://forum.ansible.com/t/issue-using-remote-user/17000/2 "2014-12-09T23:49:47Z")

</div>

I take it that what you want to happen is that you use ssh keypairs to  
log into the remote system?

To do that you'll need to have a public key for your local user in the  
both the remote system's /root/.ssh/authorized\_keys file and the  
remote system's ~yourname/.ssh/authorized\_keys file. From the looks  
of the output you have the public key setup correctly in the remote  
system's /root/.ssh/authorized\_keys file but not in the remote  
system's ~yourname/.ssh/authorized\_keys file.

The reason is that there's really two tasks being performed in your  
playbook. First, ansible runs a setup module task to gather facts  
about the remote system. Then it runs the task that you specified  
explicitly in the playbook's tasks section. Since you have  
remote\_user: root specified at the toplevel, the setup task is logging  
into the remote system as root and thus using root's authorized\_keys  
file. Then ansible gets to the second play and sees that you have a  
remote\_user set to "youruser". So it creates a second ssh connection  
to the remote system and attempts to run that task. The fact that  
it's failing for this second task means that ssh wasn't able to  
authenticate using the private keys that your local user has access  
to.

You can solve this by making sure that the yourname account on the  
remote system has the proper keys. Or you might find you don't have  
to use remote\_user: yourname at all. For instance, if you just want  
to run a command as yourname and you ar efine logging into the remote  
system as root, you could use this instead:

tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: test connection  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ping:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo\_user: yourname  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo: True

That will still log into the remote syste using the root account since  
that's specified in remote\_user at the top level but will use sudo to  
switch to the yourname account when running the "test connection" task

-Toshio
