Disabling/Deleting and Archiving Linux Accounts with the magic of "Automation"?!

Disabling/Deleting and Archiving Linux Accounts with the magic of "Automation"!

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:

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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!

No alt text provided for this image

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.

Vatsal Sharma

Senior Product Designer @ OutDefine

4 年

Woww... Nice Work brother ????

Sudhirr J Chavhan

Technology Analyst at Infosys Limited

4 年

Very useful Ashutosh Saxena

要查看或添加评论,请登录

社区洞察

其他会员也浏览了