Tuesday, November 22, 2011

Disabling User Login

I maintain one of the server in my office and that server is often being used as a hosting for some students's assignment (especially web-related assignment). Since each assignment has their own deadline, i have to limit the access for the students so that they couldn't update / upload any new files after the deadline.

So, i created a very simple bash script which uses passwd command to disable an account and set the time the script is to be executed by cron. Here's the simple script:
#!/bin/bash
/usr/bin/passwd username -l
let's say i name it lock.sh. All i need now is to set this script as executable and then add the time to crontab and it will be executed at the time defined.

Basically this command will add a character "!" to the shadow file so that user will not be able to login (because the password will be incorrect) and it's easy to solve my problem. If i need to reinstate that username again, i can just issue /usr/bin/passwd username -u and voila.... it will be able to login again.

1 comment:

  1. hiii... my name is harry. i'm a newbie.. it's really nice to have a personal blog so i can share many things to other

    ReplyDelete