# Running command as newly created user

**URL:** <https://forum.ansible.com/t/running-command-as-newly-created-user/14279>\
**Category:** Ansible Project\
**Created:** [January 6, 2014, 9:50pm UTC](https://forum.ansible.com/t/running-command-as-newly-created-user/14279 "2014-01-06T21:50:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Duncan](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@Jared\_Duncan](https://forum.ansible.com/u/Jared_Duncan)\
**Post date:** [January 6, 2014, 9:50pm UTC](https://forum.ansible.com/t/running-command-as-newly-created-user/14279/1 "2014-01-06T21:50:41Z")

</div>

Hi,

I have a scenario where I need to create a new user, and then execute commands as that user. E.g.:

- name: create user  
user: name=newUser password=hashedPass shell=/bin/bash
- name: run command as user  
shell: echo $USER \> ~/user.out  
remote\_user: newUser

However, Ansible does not know how to ssh in as newUser. What is the preferred method for doing this?

Thanks, Jared

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 6, 2014, 10:06pm UTC](https://forum.ansible.com/t/running-command-as-newly-created-user/14279/2 "2014-01-06T22:06:03Z")

</div>

If you add an intermediate ‘authorized\_keys’ to a key you already have access for that user, it should work.
