2

This question already has an answer here:

I wan to create a user on Ubuntu valid for 10 min. How can I do that if it's possible?

marked as duplicate by slm, terdon, Renan, Braiam, Faheem Mitha Feb 2 '14 at 18:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

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.

  • +1 Flagged it as a dup but UV'd your A since it's good stuff. – slm Feb 2 '14 at 18:17
  • @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 2 '14 at 18:19
1

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.

  • @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 2 '14 at 18:16
  • Thanks for the edit, I see why you use lock and not delete. – terdon Feb 2 '14 at 18:23
  • if at is not installed then we can use ( sleep 10m && usermod --lock foobar & ) isn't it? – Rahul Patil Feb 2 '14 at 18:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.