rob_7cc
rob_7cc

Reputation: 917

linux delete user account without userdel

I'd like to delete a user from a tarball that contains the files for a Linux OS (it's a tarball of the root [/] filesystem). Is there a way to do this completely and properly such that it would mimic the steps taken by the userdel command? I suppose I have two choices:

  1. Work within the OS on an actual target, use userdel and then re-tar the files. Not a problem, but I was curious about acting directly on the tarball, hence...
  2. I could mimic the steps taken by userdel: un-tar and delete all entries related to the user...according to the man page of userdel I would delete entries in /etc/group, /etc/login.defs, /etc/passwd, and /etc/shadow. Then, re-tar.

Approach (2) is attractive because I could programmatically add or delete users directly on the tarball. I'll try (2), but wondering if there would be any unintended consequences or leftover bookkeeping that I should do? Or is there another way to do this?

Upvotes: 1

Views: 2710

Answers (1)

knif3
knif3

Reputation: 41

/etc/login.defs is only called when a new user is created. That file does not need to be modified. However, a mail spool will be created for the user in the location listed in login.defs

Deleting the user from /etc/shadow and /etc/passwd will work. /etc/group is not a requirement however it cant hurt. Those three files will take care of it, You may delete the mail spool if desired.

Upvotes: 2

Related Questions