# How to simulate user first login.

**URL:** <https://forum.ansible.com/t/how-to-simulate-user-first-login/16790>\
**Category:** Ansible Project\
**Created:** [November 14, 2014, 4:28pm UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790 "2014-11-14T16:28:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zelda0102](https://avatars.discourse-cdn.com/v4/letter/z/3da27b/32.png) [@zelda0102](https://forum.ansible.com/u/zelda0102)\
**Post date:** [November 14, 2014, 4:28pm UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790/1 "2014-11-14T16:28:30Z")

</div>

My virtual machine has a setting that when the first time a user logs in, it creates a home directory for the user automatically if the user does not have a home directory.

In my script, I want to achieve: Log in as different users so that they all have home directory setup. But I’m not sure how to do it.

I tried to write this in my task:

- name: Create home dir  
remote\_user: testuser2  
shell: /usr/bin/whoami

But it threw an exception:

OpenSSH\_5.9p1-hpn13v12 Debian-ts14, OpenSSL 0.9.8zc 15 Oct 2014  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug3: key names ok: [ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ssh-rsa,ssh-dss]  
debug1: /etc/ssh/ssh\_config line 13: Applying options for \*  
debug1: auto-mux: Trying existing master  
ControlPath too long

While if I change the remote\_user to a user that has already had a home directory in the machine, it will finish successfully.

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [November 17, 2014, 9:11am UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790/2 "2014-11-17T09:11:40Z")

</div>

Hi,

Not tested idea from a bus I’m going to work right now : try login into existing account and then try to sudo to new account.

Cheers,  
Wawrzek

---

<div class="post-metadata">

**Author:** ![Greg\_Andrews](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@Greg\_Andrews](https://forum.ansible.com/u/Greg_Andrews)\
**Post date:** [November 17, 2014, 1:26pm UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790/3 "2014-11-17T13:26:22Z")

</div>

What about creating the user’s home directory when you create the user’s account? Will that not work? It would eliminate the need to perform the extra step of logging in as the user and then logging back out again.

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [November 17, 2014, 1:38pm UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790/4 "2014-11-17T13:38:01Z")

</div>

For directory (LDAP, etc..) based authentication you can create the  
home directory and copy the skel over to it. Validating permissions of  
course.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [November 17, 2014, 5:26pm UTC](https://forum.ansible.com/t/how-to-simulate-user-first-login/16790/5 "2014-11-17T17:26:52Z")

</div>

Wouldn’t running `su - USER -c true` suffice?

Andrew Latham [lathama@gmail.com](mailto:lathama@gmail.com) napisał:
