Can anyone tell me if it is possible to change the linux system password at a given time interval (ex. once every 7 days) using shell script or any other programming technique without explicitly changing it? The script should be running continuously to check if the time interval has passed and if it has, then to change the passwd to some default password mentioned in the script itself.
-
3Sounds like a bad idea to me. But it's also a better question for http://unix.stackexchange.com – luser droog Apr 07 '13 at 17:23
-
2Of course it's possible, but why!? – NPE Apr 07 '13 at 17:24
-
1If you're sure you want to do this, crontab may be the way to go. – drewmm Apr 07 '13 at 17:24
-
How are you going to be informed about your new password? – Bryan Olivier Apr 07 '13 at 17:27
-
Great! Let me take a peek at your script, so I can find out the week's password... – vonbrand Apr 07 '13 at 20:17
3 Answers
It may work to put on the cron job
passwd --expire username
This will expire the password for the given account immediately, forcing to change it at the second login. You can setup the job to run at any time policies you need, and (if run as root) this command will have effect on any specified user.
It is not secure to set some explicit password you later need to tell somehow to the user. It may be better to allow the user to think the password.

- 20,936
- 12
- 75
- 93
Use cron to schedule your script.
I agree this seems like a Bad Idea, but I don't know why you want to do this.

- 8,582
- 1
- 21
- 27
It is a Very Bad Idea. Without root, you are screwed for good. And messing with the relevant files by a script is a terrible idea on its own.
If you want to disallow root login at all, give it an impossible password (like *
in the password field in /etc/shadow
. Just make sure to have the rescue disk at hand...
Or use the "password aging", check out passwd(5)
and shadow(5)
.

- 11,412
- 8
- 32
- 52