-2

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.

3 Answers3

2

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.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
1

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.

Fred
  • 8,582
  • 1
  • 21
  • 27
0

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).

vonbrand
  • 11,412
  • 8
  • 32
  • 52