LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2012, 11:47 AM   #1
newbie0101
Member
 
Registered: Nov 2011
Posts: 47

Rep: Reputation: Disabled
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
 
Old 03-04-2012, 04:59 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
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>')
 
Old 03-04-2012, 05:15 PM   #3
PDock
Member
 
Registered: Aug 2004
Distribution: Slack10 & curr. tried numerous
Posts: 189

Rep: Reputation: 36
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.

Last edited by PDock; 03-04-2012 at 05:31 PM. Reason: dead brain cells
 
Old 03-04-2012, 07:10 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by newbie0101 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
user time, system time, real time .. reg chaitanyajun12 Linux - Newbie 7 03-14-2016 06:43 PM
deian yum lock [ ERR] Reading state information E: Could not get lock /var/lock/aptit jayakumar01 Linux - Server 1 12-05-2011 12:26 PM
Disable lock session (lock screen) when switch user in KDE 4.x Murz Linux - Desktop 4 12-01-2010 09:28 AM
how to understand user time, sys time, wait time, idle time of CPU guixingyi Linux - Server 1 08-24-2010 11:10 AM
Created user in Webmin - how to lock that user in specified directory? guest Linux - Security 1 04-18-2009 08:21 PM


All times are GMT -5. The time now is 06:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration