LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to lock user after certain time (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-lock-user-after-certain-time-932668/)

newbie0101 03-04-2012 10:47 AM

how to lock user after certain time
 
hello guys, how can one lock an user account after a specific time ?
let's say i want to set locking at 3 days from now, so if the user doesn't log in within 3 days, his account will be automatically locked, if he logs in, his account won't be locked.
i know there are commands like
Code:

usermod -L username
to lock account immediately or
Code:

chage -E 10/10/2012 username
to set expiration at that time.
but don't know how to set locking after certain time, for example 3 days from now

any suggestions ? thank you

kbp 03-04-2012 03:59 PM

You could try setting the last password change date to date of today minus the maximum password age ('chage -d YYYY-MM-DD <account>') then set the inactivity to 3 days ('chage -I 3 <account>')

PDock 03-04-2012 04:15 PM

look at bash_login

this only works if you use a command login not a graphical login.

You would put a script in .bash_login that would create a file in the users home directory with the date he logged in (if successful}. The script would also have an if statement checking if the last logindate was less than 4 days from 'date' if so update logindate to 'date' else lock account.

Success not a given just my best guess.

ppd

As script would need 'root' authority to lock the account [bad idea]; simply have the script issue the logout command if unsuccessful. Achieves same purpose.

Tinkster 03-04-2012 06:10 PM

Quote:

Originally Posted by newbie0101 (Post 4618239)
hello guys, how can one lock an user account after a specific time ?
let's say i want to set locking at 3 days from now, so if the user doesn't log in within 3 days, his account will be automatically locked, if he logs in, his account won't be locked.
i know there are commands like
Code:

usermod -L username
to lock account immediately or
Code:

chage -E 10/10/2012 username
to set expiration at that time.
but don't know how to set locking after certain time, for example 3 days from now

any suggestions ? thank you

I'd run something like (like as in: I'm just outputting "yup" where you want to actually
lock the user) this from a cron-job every morning ...
Code:

if [ $(echo "("$(date "+%s")-$(date "+%s" -d "$(last -F user|head -n 1|sed -r -e 's/^.*:0.0 +//' -e 's/ - .*$//' )")")"/3600/24| bc -iq ) -ge 4 ]; then echo yup;fi



Cheers,
Tink


All times are GMT -5. The time now is 04:40 PM.