Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've just started learning puppet and have came across a problem I was wondering if anyone knew how to fix.I m trying to remove a user I get an error message stating that they are logged in so can't be removed.

Now in this case I know what server they're logged into so I could simply just log the user out and proceed from there.My question is however what do you do when you don't know what servers they're logged into? Keeping in mind it could be many servers.

Is there a force remove option or a way to log users out in puppet?

Code below:

user {'art':

ensure => absent,



Error: Could not delete user art: Execution of '/usr/sbin/userdel art' returned 8: userdel: user art is currently logged in

Error: /Stage[main]/Main/Node[demo]/User[art]/ensure: change from present to absent failed: Could not delete user art: Execution of '/usr/sbin/userdel art' returned 8: userdel: user art is currently logged in

share|improve this question

According to this post, you can disconnect users using pkill -STOP -u USERNAME.
You can create a resource definition something this in puppet:

define kill_and_delete {
    exec { "killing $title":
        command => "pkill -STOP -u $title",
        onlyif  => "grep '^$title' /etc/passwd",
        before => User[$title],
    user { $title: ensure => absent}

Afterwards, you use it like this:
kill_and_delete {'art': }
Note: I didn't test this.
see resource ordering - before and require and type reference - exec.

share|improve this answer
You're almost there. -STOP will simply suspend the processes, not kill them. – Michael Hampton Jul 18 '14 at 11:41

You terminate a session by killing its parent process, called the session leader. Find out which process it is with:

ps -dN|grep pts/3


As mentioned by @Nitz

pkill -9 -u username

And for reference check this link:

How can I force other users to log out?

share|improve this answer

I stumbled upon the same issue when deleting a user where processes were running. I have tested my solution on our production server and therefore I can provide a valid solution where I create users in a separate class using "ensure" variables. And based upon the variable I decide whether to call the process stop sequence or not as follows:

define your_class::user (
  $user   = $name,
  $ensure = 'present',

  # only call when user gets removed
  if $ensure == 'absent' {
    exec {
      "killing ${user}":
        command => "pkill -9 -u ${user}",
        # need to check if user exists and processes are running
        # otherwise command would fail with no processes
        onlyif  => "grep '^${user}' /etc/passwd && ps -u ${user}",
        # run before user gets removed
        before  => User[$user];

  # create/remove user with managed home
  user {
      ensure     => $ensure,
      home       => "/home/${user}",
      managehome => true,
      shell      => '/bin/bash',
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.