# I am trying to disable a user and give no login access to the user.

**URL:** <https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265>\
**Category:** Ansible Project\
**Created:** [April 12, 2018, 9:11pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265 "2018-04-12T21:11:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![poojavenkateshreddy](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@poojavenkateshreddy](https://forum.ansible.com/u/poojavenkateshreddy)\
**Post date:** [April 12, 2018, 9:11pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265/1 "2018-04-12T21:11:16Z")

</div>

I am trying to disable a user and not remove it completely

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 12, 2018, 9:12pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265/2 "2018-04-12T21:12:56Z")

</div>

I typically do something like:

- name: Disable the ubuntu user  
user:  
name: ubuntu  
password: “!”  
shell: /usr/sbin/nologin

- name: Remove the ubuntu users ssh key  
file:  
path: /home/ubuntu/.ssh/authorized\_keys  
force: yes  
state: absent

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 12, 2018, 9:16pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265/3 "2018-04-12T21:16:43Z")

</div>

Or you can just expire the user :

- user:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: thatguy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expires: "{{lookup('pipe', 'date +%s')}}"

---

<div class="post-metadata">

**Author:** ![poojavenkateshreddy](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@poojavenkateshreddy](https://forum.ansible.com/u/poojavenkateshreddy)\
**Post date:** [April 12, 2018, 9:59pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265/4 "2018-04-12T21:59:03Z")

</div>

Thanks 🙂 It works!

---

<div class="post-metadata">

**Author:** ![poojavenkateshreddy](https://avatars.discourse-cdn.com/v4/letter/p/ecb155/32.png) [@poojavenkateshreddy](https://forum.ansible.com/u/poojavenkateshreddy)\
**Post date:** [April 12, 2018, 10:00pm UTC](https://forum.ansible.com/t/i-am-trying-to-disable-a-user-and-give-no-login-access-to-the-user/27265/5 "2018-04-12T22:00:10Z")

</div>

Thanks. It works 🙂
