I wan to create a user on Ubuntu valid for 10 min. How can I do that if it's possible?
2 Answers
To add a new user with an expiration date, do:
useradd -e 2014-02-03 foobar
That will create a user called foobar who will only be valid until the 3d of February 2014. From man useradd:
-e, --expiredate EXPIRE_DATE
The date on which the user account will be disabled. The date is
specified in the format YYYY-MM-DD.
I don't think it is possible to give smaller intervals than "tomorrow" however. A possible workaround would be to create a normal user and then delete that user in ten minutes:
adduser foobar && sleep 600 && deluser foobar
NOTE:
adduser is a front end to useradd. In general, on Debian based systems, adduser is to be preferred since it automates all sorts of things like creating a user directory etc. The useradd command will not do this by default so you should read it's man page to learn how it works and what options you should use.
-
-
@slm thanks :). I'm in the process of editing your linked A to add the tricks from this thread about dealing with minutes and I'll vote to close this as a dupe as well. – terdon Feb 02 '14 at 18:19
You can create the user with useradd and then schedule a usermod --lock command with at, e.g.:
# echo usermod --lock juser | at now + 10 minutes
Depending on your requirements you may want to verify what account invalidation procedure you need to execute via at.
Note that disabling an account is not trivial.
Even when deleting it - that does not necessarily mean that her current login session and all running processes are immediately terminated.
- 57,532
-
@terdon, deleting the user may be fine as well - I just picked locking because the OP talked about making it valid for 10 minutes. – maxschlepzig Feb 02 '14 at 18:16
-
-
if
atis not installed then we can use( sleep 10m && usermod --lock foobar & )isn't it? – Rahul Patil Feb 02 '14 at 18:24
pw lock <user>10 min. later. – slm Feb 02 '14 at 18:11