2

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

terdon
  • 242,166
ISMAIL
  • 81
  • 1
    What actual operating system? Is this really Unix or Linux? Which Unix? Which Linux? – terdon Feb 02 '14 at 18:02
  • @terdon i'm using Ubuntu – ISMAIL Feb 02 '14 at 18:03
  • Related: http://unix.stackexchange.com/questions/109148/how-to-control-the-time-that-users-spend-on as well as this: http://unix.stackexchange.com/questions/1181/lock-some-accounts-during-some-time-periods/1186#1186 – slm Feb 02 '14 at 18:05
  • @slm it's not that – ISMAIL Feb 02 '14 at 18:10
  • Sure you can, create the account and then set a crontab entry that will run pw lock <user> 10 min. later. – slm Feb 02 '14 at 18:11

2 Answers2

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.

terdon
  • 242,166
  • +1 Flagged it as a dup but UV'd your A since it's good stuff. – slm Feb 02 '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 02 '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.

maxschlepzig
  • 57,532