Disabling/Deleting and Archiving Linux Accounts with the magic of "Automation"!
Ashutosh Saxena
Cloud Engineer 2@Amazon Web Services | DevOps tools | 5xRedHat | 4xAWS, 1xGCP | CNCF Speaker | Teacher | Mentor
Okay! Here's another one.
We all hate the repetitive and complex tasks right? SAME! Me too :(
But don't worry, I've found a solution for you all. Are you working on a Linux system where there are many accounts which are not used now? Or the company in which you're working is one of the employee left or gone over a long holiday with his/her beloved wife/husband? And now, as an Administrator of the system, you need to disable/lock or delete the accounts for the respective users? Are you tired with "userdel [OPTIONS] username" and repeating this again and again. You don't want to delete user's home directory but you want to delete the user only use "userdel ${USERNAME}" or customize this command as per your needs. ALAS! 100 USERS? TOO MUCH OF IRRITATION!
Don't worry I've got your back.
Please check the below screenshots of the working of the script:
Don't know how to use? Don't worry here too. This script will tell you what to pass as an argument to use it.
Okay here's the magic. Here as for demonstration, I've deleted user "Tele" with "-d" flag. But as you can see, Tele's home directory is not deleted.
Proceeding further, I don't want to keep the home directory either. Hence instead of using
userdel -r ${USERNAME}
for let say 100 users. You're gone!
Just use -dr (delete and remove) home directory of the user and dope!
Okay extending this on for the last time! Archive the user's home directory and keep it in a safe folder. Here I've used a folder named "/archives". (P.S: The script can also make this if not present).
Hence instead of typing:
tar -zcf ArchiveDirectoryName /home/${USERNAME}
Just use "-a" to archive it! And boom! EXPECTO PATRONUM :p.
Senior Product Designer @ OutDefine
4 年Woww... Nice Work brother ????
Technology Analyst at Infosys Limited
4 年Very useful Ashutosh Saxena